我的应用程序中有服务需要在设备 OPPO 的后台运行。我在某处读到我们需要在应用程序设置中启用自动启动以保持服务运行,但我的权限有问题。
java.lang.SecurityException: Permission Denial: 从 ProcessRecord{904a19d 12604:elite.driver.adsmove.com.settingpermission/u0a214} 开始 Intent { cmp=com.coloros.safecenter/.startupapp.StartupAppListActivity } (pid=12604, uid= 10214) 需要 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" />
期待有这方面经验的朋友帮忙,谢谢!