Android的出现是一个以编程方式启动的应用程序不会增加表现方式?是一个、方式、应用程序、Android

2023-09-07 11:35:50 作者:血族、虎王

我只想从我的应用程序开发包的名称动态地启动一些应用程序,我已经尝试过这样的:

I would like only to start some applications dynamically with the package name from the app i develop, i already tried this:

intent = new Intent(Intent.ACTION_VIEW);
component = new ComponentName(getApplicationContext(), myPrefs.getString("Combo1", null));
Log.i("LOG", myPrefs.getString("Combo1", null));
intent.setComponent(component);

intent = pm.getLaunchIntentForPackage(myPrefs.getString("Combo1", null));
startActivity(intent);

两部作品和多个应用程序打开,但其他的我得到这个错误。

both works and several applications opens but for others i get this error.

11-29 21:42:08.723: E/AndroidRuntime(4719): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.lock/com.sec.android.app.phoneutil}; have you declared this activity in your AndroidManifest.xml?

我理解错误(即我需要添加在清单中的应用程序/活动),所以我想知道,如果是一个解决方法,动态添加的活动来体现,或者有不增加,以动态地启动应用程序的方式清单应用程序/活动,或者有允许打开应用程序的权限?

I understand the error(that i need to add the app/activity in manifest), so i want to know if is a workaround to add dynamically activities to manifest, or there is a way to start dynamically an application without adding to the manifest that app/activity, or there is a permission that allow to open applications ?

从我的研究似乎是不可能的,但我想知道专家的意见。

From my research it seems impossible, but i want to know the opinion of an expert.

感谢名单提前。

推荐答案

如果你正在谈论从你启动其他应用程序,这是你需要的code:

If you are talking about launching other apps from yours, this is the code you need:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packageName,mainActivity));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);

您可以得到的主要活动是这样的:

You can get the main activity like this:

Intent mIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName); 
if (mIntent != null) {
    if (mIntent.getComponent() != null) {
    mainActivity = mIntent.getComponent().getClassName();
    }
}
 
精彩推荐
图片推荐