Java的Andr​​oid开的pid从进程名称,但不知道它的全名它的、全名、但不、进程

2023-09-12 23:58:27 作者:狂野男孩

即时通讯编码一个Android应用程序嗨。现在我要去的一部分。在该应用程序应该杀的过程。但我不知道它的全名或它的PID。我知道这个命令:

Hi im coding an android application. Now im going to a part where the application should kill a process. but i dont know its full name or its pid. I Know the commands:

android.os.Process.killProcess(Pid)

android.os.Process.getUidForName("com.android.email")

但我的问题是,我不知道该进程的全名。

But my problem is that i dont know the full name of the process.

它的原生code的过程,所以不会像com.something.something

its an native code process, so not something like com.something.something

这个过程是 /data/data/com.something.something/mybinary

但它与命令运行像

/data/data/com.something.something/mybinary -a 123 -b 456

这一点,因为我不能用

because of this i cant use

android.os.Process.getUidForName("/data/data/com.something.something/mybinary")

任何人有帮助吗?

Anyone got help please?

推荐答案

您可以使用:

ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
 List<RunningAppProcessInfo> services = manager.getRunningAppProcesses();
 String service1name = services[1].processName;

您可以得到所有正在运行的进程的包名,选中要杀人,选择过程中获取进程的ID service.pid其中之一。

You can get all running process's package names, check which one you want to kill, choose that process get process id by service.pid.

和调用:

android.os.Process.killProcess(service.pid);