根据Android Management API 参考,我们将 Android Companion 应用程序配置为能够:启用系统应用程序、隐藏和取消隐藏包。
我们在策略配置中添加了以下信息:
{
'
'
'
"applications": [
{
"packageName": "com.domain.app",
"installType": "REQUIRED_FOR_SETUP",
"defaultPermissionPolicy": "GRANT",
"delegatedScopes": [
"ENABLE_SYSTEM_APP",
"PACKAGE_ACCESS"
]
}
],
'
'
'
}
然后,在我们的 Android Companion 应用程序中,我们根据此处和此处的 Google 文档添加了以下代码行:
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName admin = new ComponentName(mContext, DeviceAdminReceiver.class);
// Iterate through system application package names list
for (String packageName : systemAppsList) {
if (packageName != null && !packageName.equals("")) {
try {
// Re-enable a system app that was disabled by default when the user was initialized
dpm.enableSystemApp(admin, packageName);
// Unhide a package (it could be any app : system, managed, etc...)
dpm.setApplicationHidden(admin, packageName, false);
} catch (SecurityException e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
}
}
}
我们希望 Android 启动器显示启用的系统应用程序,但 Android 捕获SecurityException
并打印以下错误日志:
没有活动管理员 ComponentInfo{com.domain.app/android.app.admin.DeviceAdminReceiver}
您对可能出现的问题有任何想法吗?