android - 我可以使用广播接收器启动另一个应用程序吗?

标签 android android-broadcast

我只是想知道我已经创建了一个应用程序并将其安装在我的设备上。是否可以仅使用广播接收器来启动该应用程序,如果可以,我该怎么做?

最佳答案

在您的应用程序未运行时使用以下代码打开 Activity。

Intent myIntent = new Intent(context.getApplicationContext(), YourClassActivity.class);
Bundle bundle = new Bundle();
myIntent.putExtras(bundle);
myIntent.addFlags(
      Intent.FLAG_ACTIVITY_NEW_TASK
    | Intent.FLAG_ACTIVITY_CLEAR_TOP
    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.getApplicationContext().startActivity(myIntent);

你可以在 bundle 中传递任何数据,比如

bundle.putString("title", "from receiver");

关于android - 我可以使用广播接收器启动另一个应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15111140/

相关文章:

Android CursorAdapter 在错误的列表项中绘制内容

android - 图片预览太长

android - ble 客户端特征配置描述符中的 ENABLE_INDICATION_VALUE 和 ENABLE_NOTIFICATION_VALUE 是什么?

Android - 如何触发广播接收器调用其 onReceive() 方法?

Android 应用程序卸载监听器

android - 如何从启动另一个应用程序的应用程序中获取额外的 Intent ?

Android EGL sRGB 默认渲染缓冲区

java - Android:从服务接收和转发短信

Android 日历 BroadcastReceiver 主机 : com. android.calendar 与 com.google.android.calendar

java - BroadcastReceiver 中如何直接使用方法 "getSystemService"?