android - 启动系统上的任何 Activity

标签 android android-activity

我试图允许用户提供类名,然后启动Activity,但我不断收到错误消息:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.intel.ave.androidclient/com.android.vending}; have you declared this Activity in your AndroidManifest.xml?

我没有将其放入 list 中,因为我不知道用户在运行时想要什么。

//package_name = input from the user
//MyContext = the activity context
Intent newprocess = new Intent(Intent.ACTION_MAIN);
newprocess.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newprocess.setClassName(MyContext, package_name);
MyContext.startActivity(newprocess );

最佳答案

有 Intent 地启动外部 Activity 与在应用程序内启动有点不同。请参阅calling activity from external Activity 。引用那里,你会用这个来代替

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.the.other.app");
startActivity(intent);

关于android - 启动系统上的任何 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454448/

相关文章:

android - 使用 recreate() 方法和 startActivity(getIntent()) 重新创建 Activity 的区别

android - 强制应用程序从第一个 Activity 重新启动(当权限被拒绝时)

android - setMyLocationEnabled 函数在 Android Studio 中不起作用

android - 从我在 android 中的 Activity 访问任何电子邮件收件箱

java - 如何在java中的多个类中使用一个接口(interface)?

android - Flutter Plugin 使用 Kotlin,Activity 总是返回 null

java - 卸载Android Studio,但保留android SDK

java - WorkManager 适用于 Oreo 但不适用于 Lollipop

android - 如何从 CallScreeningService 的 Call.Details 中提取电话号码?

android - 在 Android 上使用 textview 写一段话