我的应用程序中有一个需要在OPPO设备后台运行的服务。我在某处读到过,我们需要在设置中启用自动启动以使app的服务保持运行,但我遇到了权限问题。
java.lang.SecurityException:Permission Denial:starting Intent { cmp = com.coloros.safecenter / .startupapp.StartupAppListActivity } from ProcessRecord {904a19d 12604:elite.driver.adsmove.com.settingpermission / u0a214}(pid = 12604,uid = 10214)requires oppo.permission.OPPO_COMPONENT_SAFE
当我尝试这样做时
if (Build.MANUFACTURER.equals("OPPO")) {
Intent[] AUTO_START_OPPO = {
new Intent().setComponent(new ComponentName("com.coloros.safe", "com.coloros.safe.permission.startup.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.coloros.safe", "com.coloros.safe.permission.startupapp.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startup.StartupAppListActivity"))
};
for (Intent intent : AUTO_START_OPPO) {
if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
try {
startActivity(intent);
break;
} catch (Exception e) {
Log.d(TAG, "OPPO - Exception: "+ e.toString());
}
}
}
}
我也尝试添加权限并请求它,但失败了
<!--for OPPO-->
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE" />
期待有经验的人提供帮助,谢谢!