Android按组件名称调用OEM活动

Android按组件名称调用OEM活动,android,adb,Android,Adb,在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/.Sys

在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?
我们能做些什么来克服这个问题?我把意图说错了吗?

弄明白了:)

Context foreignContext=createPackageContext(“com.android.settings”,Context.Context_IGNORE_SECURITY | Context.Context_INCLUDE_code);
Class yourClass=foreignContext.getClassLoader().loadClass(“com.android.settings.SystemUpgradeCheck”);
意向意向=新意向(国外背景,你的职业);
星触觉(意向);
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);