How Do Android Monitor Usage Applications Work
I want to write an application that logs the usage of other applications on my phone. So for example I get the times I have entered Facebook. I understand there is no way to get a
Solution 1:
The only way to monitor other apps is by monitoring foreground activity. This will drain your battery but there is no broadcast when other apps are launched and hence no other way to do it. You would like to start a timer task that checks the current foreground activity. I would highly recommend not to do it. To get current foreground activity use the following code:
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
Log.d("topActivity", "CURRENT Activity ::"
+ taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();
You will need the following permission:
<uses-permissionandroid:name="android.permission.GET_TASKS"/>
Post a Comment for "How Do Android Monitor Usage Applications Work"