Newstrong's 博客

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

Android中进程相关信息获取,pid,进程名

2024年9月20日 5点热度 0人点赞 0条评论

1. 获取pid

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

2. 获取进程名及其他信息

ActivityManager mActivityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
        .getRunningAppProcesses()) {
    if (appProcess.pid == pid) {
        procName = appProcess.processName;
    }
}

appProcess中可以获取一些进程相关的信息,如:

        /**
         * The name of the process that this object is associated with
         */
        public String processName;

        /**
         * The pid of this process; 0 if none
         */
        public int pid;

        /**
         * The user id of this process.
         */
        public int uid;

        /**
         * All packages that have been loaded into the process.
    

文章来源于互联网:Android中进程相关信息获取,pid,进程名

标签: 暂无
最后更新:2026年6月22日

newstrong

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 6 月
  • 2026 年 1 月
  • 2025 年 3 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2021 年 4 月
  • 2020 年 5 月

分类

  • Android
  • git
  • 性能优化
  • 未分类

COPYRIGHT © 2026 Newstrong's 博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang