在Huwaie Ascend上,当我们浏览设置菜单时:
Settings -> SD card & phone storage -> Software Upgrade -> SD card Upgrade
然后我们将进入用户可以升级的屏幕。
然后使用adb logcat我们看到:
Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.SystemUpgradeCheck }
我们可以通过调用:
使用adb来模拟这个adb shell am start -n com.android.settings/.SystemUpgradeCheck
这很成功,我们看到了屏幕。
但是,当我们尝试在这样的活动中调用它时:
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("com.android.settings", ".SystemUpgradeCheck"));
startActivity(i);
我们收到此错误:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/.SystemUpgradeCheck}; have you declared this activity in your AndroidManifest.xml?
我们可以做些什么来克服这个问题?我的意图是错误的吗?
答案 0 :(得分:3)
弄明白:)
Context foreignContext = createPackageContext("com.android.settings", Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
Class<?> yourClass = foreignContext.getClassLoader().loadClass("com.android.settings.SystemUpgradeCheck");
Intent intent = new Intent(foreignContext, yourClass);
startActivity(intent);