1. 程式人生 > >如何獲取當前應用app所在的程序id和程序名稱

如何獲取當前應用app所在的程序id和程序名稱

int pid = Process.myPid();
        String processName = "";
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

        List<ActivityManager.RunningAppProcessInfo> list = activityManager.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : list){
            if (runningAppProcessInfo.pid == pid){
                processName = runningAppProcessInfo.processName;
            }
        }

        Log.i(TAG,"當前程序名稱:" + processName);