如何获得可运行的应用程序包名称

时间:2017-05-12 09:14:04

标签: java android

我试过但是当api水平高于20时我没有得到回应。 (响应变为空)。

ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
String activityOnTop;
if (Build.VERSION.SDK_INT > 20) {

    activityOnTop = mActivityManager.getRunningAppProcesses().get(1).processName;
} else {
    List<ActivityManager.RunningTaskInfo> RunningTask1 = mActivityManager
            .getRunningTasks(1);
    ActivityManager.RunningTaskInfo ar1 = RunningTask1.get(0);
    activityOnTop = ar1.topActivity.getPackageName();
}

Log.e("activityOnTop", "!!!!!!!!!!" + activityOnTop);

0 个答案:

没有答案