Monitoring the current application

I am facing a problem that I cannot solve at the moment.
The purpose of the code is to control which applications are currently running.
I used the following code and registered the resulting package name, it worked.

ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);  
String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();  
Log.i("TTWYMonitor", packageName);

      

But I am using this code in BroadcastReceiver

, nothing happened. In manifest

I announced the receiver intent android:name=".MonitorApplication.


What to do, then? Please give any suggestion.

Yahel : Thanks and sorry for my informal question.

0


source to share


1 answer


replace "Activity" in the getSystemService parameters with "Context":

ActivityManager  manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

      



I tested it and it worked great for me!

0


source







All Articles