Android, 다른 앱이 실행될 때 감지
사용자가 암호없이 지정된 앱에 액세스하지 못하도록하는 앱을 개발하려고합니다. 시나리오는 ...
- 사용자가 "이메일"앱을 클릭 함 (예 :)
- 내 앱이 앱 실행을 감지합니다.
- 내 앱이 "이메일"앱인지 확인합니다
- 내 앱은 상단에보기를 열어 비밀번호를 요청합니다.
- 사용자가 비밀번호를 입력하면 내 앱이 사라지고 "이메일"앱이 맨 위에 남습니다.
나머지는 괜찮습니다. 2 부만 헷갈리네요. 며칠 동안 Broadcast Intents 등을 읽고 평가판 프로젝트에서 "android.intent.action.MAIN"등을 들으려고 시도한 후에는 할 수 없습니다. 내 앱이 아닌 다른 앱이 시작되면 감지하는 것 같습니다.
누구든지 도울 수 있습니까? 시작할 인 텐트를 브로드 캐스팅하는 새 앱을 찾거나 새 인 텐트에 대한 시스템 로그를 읽거나 네이티브 코드로 작업을 수행해야 하는가?
모든 조언이 도움이 될 것입니다. 완전히 대답 할 수 없더라도 더 많은 조사를 할 수있을 것입니다. 감사합니다. 이안
그 logcat
결과물을 사용 하고 분석 할 수 있다고 생각 합니다.
모든 유사한 프로그램에서이 권한을 찾았습니다.
android.permission.READ_LOGS
그것은 그들 모두가 그것을 사용한다는 것을 의미하지만 프로그램이 시작되고 그 후에 우리 프로그램 (앱 보호기)이 시작되고 앞으로 나아갈 것입니다.
아래 코드를 사용하십시오.
try
{
Process mLogcatProc = null;
BufferedReader reader = null;
mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
String line;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null)
{
log.append(line);
log.append(separator);
}
String w = log.toString();
Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
그리고 Manifest 파일에 권한을 추가하는 것을 잊지 마십시오.
이를위한 변칙적 인 방법은 검사하는 timed 루프가있는 서비스를 사용하는 것입니다.
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
You run through that list to look at what is running on the phone. Now you can identify them with ids and processName, so for standard activity this is easy for custom ones well unless you stop them all its hard to discriminate...
Note: this isnt a list of whats is actually on the screen, just a list of whats is running...kinda nullifying your goal maybe but at least you will know when something is starting to run... it will keep being in that list even when in background though.
For the password thing you can just start your activity when you found an app thats protected or whatever.
I think and hope this is not possible. Consider how easily such functionality could be abused by malicious software. You can listen to intents directed at you, and those that are broadcast, but application launching should not be a broadcast event.
What you may be able to do is replace the launcher. If the user agrees to it.
class CheckRunningActivity extends Thread{
ActivityManager am = null;
Context context = null;
public CheckRunningActivity(Context con){
context = con;
am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
public void run(){
Looper.prepare();
while(true){
// Return a list of the tasks that are currently running,
// with the most recent being first and older ones after in order.
// Taken 1 inside getRunningTasks method means want to take only
// top activity from stack and forgot the olders.
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
String currentRunningActivityName = taskInfo.get(0).topActivity.getClassName();
if (currentRunningActivityName.equals("PACKAGE_NAME.ACTIVITY_NAME")) {
// show your activity here on top of PACKAGE_NAME.ACTIVITY_NAME
}
}
Looper.loop();
}
}
You can get current running Activity
and check if this Activity
corresponds to Email
application.
Run CheckRunningActivity
Thread
on Application
start (or on device boot).
new CheckRunningActivity().start();
Update: This class need android.permission.GET_TASKS
permission, so add next line to the Manifest:
<uses-permission android:name="android.permission.GET_TASKS" />
The main issue is you are trying to listen for implicit intents when the Launcher (home screen) is typically using explicit intents.
An implicit intent is when you want to say "Somebody play this video" and Android picks an app that can handle that intent.
An explicit intent is what happens when you click the "Email" icon on the home screen. It is specifically telling Android to open that specific app by fully qualified name (i.e. com.android.mail or something).
There is no way AFAIK to intercept such explicit intents. It is a security measure built into Android that no two Activities can have the same fully qualified package name. This prevents a third party from cloning the app and masquerading as that app. If what you wish to do was possible, you could theoretically install an app that could block all of your competition's apps from working.
What you are trying to do goes against the Android security model.
One thing you could do is partner with specific app developers to forward the intents to your security system, but that's probably not something you want to deal with.
getRunningTasks()
is deprecated in Android L.
To obtain app usage statistics you can use UsageStats class from android.app.usage package.
The new App usage statistics API allows app developers to collect statistics related to usage of the applications. This API provides more detailed usage information than the deprecated getRecentTasks() method.
To use this API, you must first declare the android.permission.PACKAGE_USAGE_STATS
permission in your manifest. The user must also enable access for this app through Settings > Security > Apps with usage access
.
Here is a basic app example showing how to use App usage statistics API to let users collect statistics related to usage of the applications.
Perhaps you need a service, something that will run in the background constantly. Than have your service do what you said. Listen for the android.intent.action.MAIN also with the category android.intent.category.LAUNCHER. Then have that broadcast receiver override the onReceive method and do check to see the name of the application etc.
참고URL : https://stackoverflow.com/questions/3290936/android-detect-when-other-apps-are-launched
'developer tip' 카테고리의 다른 글
두 개체를 비교하고 차이점 찾기 (0) | 2020.09.07 |
---|---|
new Date ()는 Chrome과 Firefox에서 다르게 작동합니다. (0) | 2020.09.06 |
Swift에서 하나 이상의 프로토콜을 준수하는 특정 유형의 변수를 어떻게 선언 할 수 있습니까? (0) | 2020.09.06 |
무엇이 유효하고 URI 쿼리에없는 것은 무엇입니까? (0) | 2020.09.06 |
하나의 단위 테스트는 Express로 어떻게 라우팅됩니까? (0) | 2020.09.06 |