我们可以在AndroidManifest.xml
中为 Activity 或服务定义android:process
,命名为子进程。
例如,我的包名称是 'com.test.main'
并且我定义了两个子流程:
android:process=":tool"
android:process=":bar"
我的问题是:
将apk文件安装到android设备后,我们如何获取所有这些子进程列表信息,例如com.test.main:tool
,com.test.main:bar
,通过 adb 或其他已安装的应用程序?
最佳答案
String pkg = "com.google.android.gms";
try {
// Ref: https://developer.android.com/guide/components/processes-and-threads
PackageInfo packageInfo = getPackageManager().getPackageInfo(pkg, PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS);
List<ComponentInfo> list = new ArrayList<>();
if (packageInfo.activities != null) Collections.addAll(list, packageInfo.activities);
if (packageInfo.services != null) Collections.addAll(list, packageInfo.services);
if (packageInfo.receivers != null) Collections.addAll(list, packageInfo.receivers);
if (packageInfo.providers != null) Collections.addAll(list, packageInfo.providers);
for (ComponentInfo componentInfo : list) {
Utils.log("componentInfo: " + componentInfo.processName);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
关于android - 如何在Android设备上获取已安装apk的子进程信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54456402/