Google API 允许我们从方法中获取设备中所有 Activity 管理员的列表:getActiveAdmins()。但是,我的要求是我想要设备中所有可能的管理员的列表,无论是否处于 Activity 状态。有什么方法可以做到吗?
谢谢
最佳答案
您可以通过以下代码找到应用程序列表
final Intent deviceAdminIntent = new Intent("android.app.action.DEVICE_ADMIN_ENABLED", null);
final List<ResolveInfo> pkgAppsList = getPackageManager().queryBroadcastReceivers(deviceAdminIntent, 0);
for (ResolveInfo aResolveInfo : pkgAppsList) {
String pkg = aResolveInfo.activityInfo.applicationInfo.packageName;
String name = aResolveInfo.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();
System.out.println("Package :: " + pkg);
System.out.println("Name :: " + name);
}
您可以在应用程序的 ResolveInfo 中获取所有必要的数据。您可以查看 ResolveInfo javadoc here .
我写了一个返回 ComponentName 的方法与getActiveAdmins相同
private List<ComponentName> getAllAdmins(Context mContext) {
List<ComponentName> result = new ArrayList<ComponentName>();
// Read all receivers who can listen android.app.action.DEVICE_ADMIN_ENABLED
// You can add all other action which can be used for DeviceAdminReceiver
final Intent deviceAdminIntent = new Intent("android.app.action.DEVICE_ADMIN_ENABLED", null);
final List<ResolveInfo> pkgAppsList = mContext.getPackageManager().queryBroadcastReceivers(deviceAdminIntent, 0);
for (ResolveInfo aResolveInfo : pkgAppsList) {
// Prepare component and add to list
result.add(new ComponentName(aResolveInfo.activityInfo.applicationInfo.packageName,
aResolveInfo.activityInfo.name));
//String pkg = aResolveInfo.activityInfo.applicationInfo.packageName;
//String name = aResolveInfo.activityInfo.applicationInfo.loadLabel(getPackageManager()).toString();
//System.out.println("Package :: " + pkg);
//System.out.println("Name :: " + name);
}
return result;
}
关于android - 如何获取 android 中所有设备管理员( Activity 和非 Activity )的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19240322/