简体   繁体   中英

How to get pid of android application with out using adb shell?

how can i get android application pid with out using adb shell.is there any api to get pid . any help will be appreciated

由于每个应用程序都有自己的进程ID,因此可以获得它

int pid = android.os.Process.myPid();

This also works:

ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pids = am.getRunningAppProcesses();
int processid = 0;
for (int i = 0; i < pids.size(); i++) {
    ActivityManager.RunningAppProcessInfo info = pids.get(i);
    if (info.processName.equalsIgnoreCase("here your package name")) {
       processid = info.pid;
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM