android - 你能在本地广播中使用待处理的 Intent 吗?

标签 android android-broadcast android-pendingintent

我有兴趣在本地广播中使用挂起的 Intent 。 为了清楚起见,我使用以下内容来注册接收器和发送广播:android.support.v4.content.LocalBroadcastManager

我在服务中有一个本地广播接收器可以正常工作。我正在尝试从包含可点击项目的自定义通知布局发送本地广播。

本地广播接收器 - 只接收简单的 Action Intent 。 我正在尝试这样的事情无济于事:

Intent backintent = new Intent("GOTO_START_BROADCAST");
PendingIntent backIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, backintent, 0);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setOnClickPendingIntent(R.id.imageView1, backIntent);

最佳答案

I am interested in using pending intents with local broadcasts.

那是不可能的。

PendingIntent 背后的要点是允许一些其他进程 执行您请求的操作,例如发送广播。

LocalBroadcastManager 背后的要点是在您的进程中保持广播

因此,PendingIntent 可以发出常规广播,但不能通过 LocalBroadcastManager 发出。

关于android - 你能在本地广播中使用待处理的 Intent 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15790734/

相关文章:

android - 为 ACTION_BOOT_COMPLETED 动态注册 BroadcastReceiver 不起作用?

Android - 清除任务标志不适用于 PendingIntent

android - 如何查询图库中相册的数量

android - Cordova 运行 Android 平台时出错

java - Android - 无法在我的 Activity 中从服务接收本地广播

android - 重新启动应用程序失败 android

android - 报警服务崩溃

android - 如何检查 View 在 Android 中是否可见?

java - ViewModel 如何在配置更改时持久化

android - 闹钟管理器在 Android 6.0 上无法在后台运行