getRunningAppProcesses

getRunningAppProcesses

本文介绍了Android 6.0:获取当前活动的程序包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取当前活动包名称?因为getRunningAppProcesses()在Android 6.0中不起作用.

How to get current activity package name? as getRunningAppProcesses() not working in Android 6.0.

下面是我的代码:

grdPhoto.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        //get package name of current running application.
        ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        packageName = mActivityManager.getRunningAppProcesses().get(1).processName;

        Log.e("Package name:===========      ", "Package name     " + packageName);

    }
});

推荐答案

获取程序包名称:

getApplicationContext().getPackageName();

也请参考此内容:获取包名称.

这篇关于Android 6.0:获取当前活动的程序包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:36