How to monitoring app swaping in foreground?

后端 未结 3 766
旧巷少年郎
旧巷少年郎 2021-01-22 22:10

when my application run in background. It need to monitoring others application swaping in the foreground and get their name. How to implement? i.e. When an app goto the for

3条回答
  •  醉话见心
    2021-01-22 22:45

    For monitoring other Applications you can use ActivityManager for getting current top Appliction for Activity Stack as in Your Appliction:

    ActivityManager am = (ActivityManager)context.getSystemService(Context. ACTIVITY_SERVICE);
    List processes1 = activityManager.getRunningTasks(1);
    ComponentName componentInfo = processes1.get(0).topActivity;
    String classname =processes1.get(0).topActivity.getClassName(); 
    String packagename = processes1.get(0).topActivity.getPackageName();
    

提交回复
热议问题