Track The Launch Of A Third-party Application
Solution 1:
Yes, it's possible in Android. You can check whether third party application is in forground or is in background using below code
classForegroundCheckTaskextendsAsyncTask<Context, Void, Boolean> {
@Overrideprotected Boolean doInBackground(Context... params) {
finalContextcontext= params[0].getApplicationContext();
return isAppOnForeground(context);
}
privatebooleanisAppOnForeground(Context context) {
ActivityManageractivityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
returnfalse;
}
finalStringpackageName= context.getPackageName();
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) {
returntrue;
}
}
returnfalse;
}
}
Solution 2:
There is no broadcast as such to inform about launch of an application to which others can listen because that can be a security threat. People can use it for malicious purpose. Otherwise from the logs you can get to know about currently launched application.
Solution 3:
First, answer your question, Is it possible to track the launch of a third-party application on the device? - YES
Check this link, I explained briefly.
Note: We should be aware of few things before doing few things
Running a while loop or timer continuously and getting the recent app will drain a lot of battery(All the AppLocker will do same to get the current opening app) but we should be smart enough and we should run the loop only when the screen ON, when screen OFF we should stop that timer or whatever.
From Android "O" some restriction in running the service in background, so better put your service as Foreground service
Done!!!.
Post a Comment for "Track The Launch Of A Third-party Application"