android - 如何从 Activity 中启动另一个应用程序(下载或预安装)?

标签 android android-activity

基本上,我想获取所有已安装应用的列表,并从 Activity 中选择一个运行。

我已经尝试过使用 Intents 的 ACTION_PICK,但这似乎遗漏了已下载的应用程序,并且其中有一堆垃圾。

谢谢

最佳答案

// to get the list of apps you can launch
Intent intent = new Intent(ACTION_MAIN);
intent.addCategory(CATEGORY_LAUNCHER);
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(intent, 0);

// resolveInfo.activityInfo.packageName = packageName
// resolveInfo.activityInfo.name = className
// reusing that intent
intent.setClassName(packageName, className);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent)

希望这足以帮助您弄明白。

关于android - 如何从 Activity 中启动另一个应用程序(下载或预安装)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2664353/

相关文章:

android - 开始 Activity 而不显示它

android - 找不到 com.android.tools.build :aapt2:3. 2.0

android - Android 对象上的 Away3DLite 没有出现在屏幕上

android - v4 getFragmentManager 与 Activity - 不兼容的类型

android - 如何通过单击通知恢复之前的 Activity

Android 如何从 TabHost Activity 中将额外内容添加到 Activity 中?

java - 如何知道应用程序用户是否离线android应用程序?

Android R 类显示为空

android - 带有预览的搜索栏,例如 youtube

android - 异步任务 OnPreExecute 方法 Android 中的进度对话框