我在我的华为nexus6p上将应用程序放在受保护的应用程序列表中时,收到了这个错误。
"UncaughtException: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.huawei.systemmanager/com.huawei.systemmanager.optimize.process.ProtectActivity}; have you declared this activity in your AndroidManifest.xml?"我正在使用此代码将应用程序放入受保护的应用程序列表中
if ("huawei".equalsIgnoreCase(Build.MANUFACTURER) && !settingsManager.getKeyStateProtectedApp()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Is app killing?").setMessage("Add LastingSales to protected apps list to keep it running in background.")
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
settingsManager.setKeyStateProtectedApp(true);
}
}).create().show();
}这里的问题是,这不是我自己的活动,我可以在清单中声明。我还需要在清单中声明它吗?如果我真的不得不这么做,那我该怎么做呢?
已解决
原因是华为nexus6p是纯android的,因此没有这样的活动。但是因为Build.MANUFACTURER返回了“华为”,所以代码就掉到了那里。然而,Build.BRAND返回"google“,因此添加了额外的检查,如
if ("huawei".equalsIgnoreCase(Build.MANUFACTURER) && !"google".equalsIgnoreCase(Build.BRAND) && !settingsManager.getKeyStateProtectedApp()发布于 2018-01-01 00:44:05
The The The
子句需要仔细检查制造商和品牌,以便它只在适合的手机上运行。
发布于 2021-01-29 23:00:42
我使用这个方法来检查设备是否可以打开这样的意图,但是对于华为,它仍然返回true,但仍然崩溃,讨厌这个制造商
fun Intent.canBeHandled(packageManager: PackageManager): Boolean {
return resolveActivity(packageManager) != null
}致命异常: android.content.ActivityNotFoundException找不到显式的活动类{com.huawei.systemmanager/com.huawei.systemmanager.optimize.process.ProtectActivity};您是否在AndroidManifest.xml中声明了此活动?com.helge.droiddashcam.base.utils.IntentUtil.autoStartSettings
https://stackoverflow.com/questions/47786535
复制相似问题