String callerPackage = getAppNameByPID(getContext(), Binder.getCallingPid());
private String getAppNameByPID(Context context, int callingPid) {
//How ?
....
}
如题,如何通过pid获取app包的名字?
String callerPackage = getAppNameByPID(getContext(), Binder.getCallingPid());
private String getAppNameByPID(Context context, int callingPid) {
//How ?
....
}
如题,如何通过pid获取app包的名字?
通过ActivityManager.getRunningProcesses和getRunningServices来获得,然后比对列表中的pid即可。
注意,1个pid有可能会对应多个package。