Android M: How can I get the current foreground activity package name(from a service)

后端 未结 2 1554
無奈伤痛
無奈伤痛 2021-01-06 01:45

It is easy to get a list of running tasks from the ActivityManager service on Android L, and the current active task is returned first. But it don\'t work on Android M any m

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 02:33

    Please try this lines in Android M. This worked for me

    String packageName =  ProcessManager.getRunningForegroundApps(getApplicationContext()).get(0).getPackageName();
    

    check below link for other android platform support.

    https://stackoverflow.com/a/36660429/4554069

提交回复
热议问题