For my Masters Thesis I´m developing an Android logger which should log, besides other parameters, which apps get started by the user. So I got a running Service and my app is not in the foreground. At the moment I´m doing this by triggering an broadcastreceiver
public void AppAlarmManager(Context context) {
Log.i(TAG, "AppAlarmManager");
AlarmManager ama = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AppReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
ama.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(2 * 1000), pendingIntent);
}
In the broadcastreceivers onReceive method I´m calling this method:
public void getAppName(Context context) {
// Log.i(TAG, "getAppName");
acm = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = acm.getRunningTasks(1);
for (RunningTaskInfo runningTaskInfo : taskInfo) {
PackageManager pm = context.getPackageManager();
ComponentName comName = runningTaskInfo.baseActivity;
String Packname = comName.getPackageName();
try {
ApplicationInfo appInfo = pm.getApplicationInfo(Packname, 0);
applicationName = (String) (appInfo != null ? pm
.getApplicationLabel(appInfo) : "(unknown)");
packageName = pm.getApplicationInfo(Packname, 0).packageName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}....}
and then I can write the app name in my database.
Up to Android 4.4.2 everything is working flawless and all started apps are listed in my database.
But since i put Android L on my Nexus 5 only the first app after my App gets closed (mostly the Launcher) gets written to my database and the broadcastreceiver will not be triggered until I open my app again.
So you got any suggestions what I can do to log started apps with Android L?
0 comments:
Post a Comment