How can I detect the execution of specific applications?

advertisements

i want to detect gallery applications running using service

so i found ActivityManager but it returned only running service own application

here is my java code

            ActivityManager actMng = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
            String strPackage = "";
            List<ActivityManager.RunningAppProcessInfo> list = actMng.getRunningAppProcesses();
            for(int i=0;i<list.size();i++){
                Log.d("test",list.get(i).processName);
            }

how can i detect gallery application run


Try this Code:

ActivityManager activity_manager = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);

Using Activity Manager to list all running apps:

final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++)
{
    Log.d("Running apps", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}