I want to know if it is possible to know the application in use by the user. Currently, I manage to get the list of active processes on the foreground but unfortunately it does not isolate the specific application for ca also taking applications in the status bar.
Here's what I use:
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses)
{
if(appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
{
Log.d("Executed app", "Foreground " +appProcess.processName + "\t\t ID: " + appProcess.pid);
}
}
Here is what I get:
11-09 18:12:56.645 8821-8821/company.test D/Executed app﹕ Foreground company.gillot.test ID: 8821 11-09 18:12:56.645
8821-8821/company.test D/Executed app﹕ Foreground android.process.acore ID: 30279 11-09 18:12:56.645
8821-8821/company.test D/Executed app﹕ Foreground com.android.phone
ID: 197 11-09 18:12:56.645 8821-8821/company.test D/Executed app﹕ Foreground system ID: 97
Anyone have an idea? I browse the forums and the android api but so far nothing specific property.
BONUS:
Thereafter I would avoid detected applications "system".
Thank you in advance.