通知操作按钮不会触发待定意图

编程入门 行业动态 更新时间:2024-10-22 20:42:40
本文介绍了通知操作按钮不会触发待定意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试从通知操作按钮向BroadcastReceiver发送意图,但是我的问题是,当我单击按钮时,意图没有触发或没有到达BroadcastReceiver.

I try to send intent to BroadcastReceiver from notification action button my problem is that when I click the button the intent in not fired or not getting to the BroadcastReceiver.

这是我的代码:

通知:

Intent accept = new Intent(this, ChallengesActionReceiver.class); accept.setAction("com.soinfit.utilities.CHALLENGE_CLICK"); accept.putExtra("reqId", extras.getString("reqId")); accept.putExtra("answer", "1"); PendingIntent acceptIntent = PendingIntent.getActivity(this, 1, accept, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setLargeIcon(image) .setSmallIcon(R.drawable.app_icon_small) .setContentTitle("soInFit") .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .setAutoCancel(true) .addAction(R.drawable.app_icon_small, getString(R.string.accept), acceptIntent) .setContentText(msg); mBuilder.setContentIntent(contentIntent); Notification nof = mBuilder.getNotification(); nof.defaults|= Notification.DEFAULT_SOUND; nof.defaults|= Notification.DEFAULT_LIGHTS; nof.defaults|= Notification.DEFAULT_VIBRATE; nof.flags = Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager = (NotificationManager) this.getSystemService(this.NOTIFICATION_SERVICE); notificationManager.notify(id+1, nof);

BroadcastReceiver

The BroadcastReceiver

public class ChallengesActionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.i("test", "test"); } }

清单:

<receiver android:name="utilities.ChallengesActionReceiver" android:enabled="true" > <intent-filter> <action android:name="com.soinfit.utilities.CHALLENGE_CLICK" /> </intent-filter>

如果我调用此代码:

Intent accept = new Intent(this, ChallengesActionReceiver.class); accept.setAction("com.soinfit.utilities.CHALLENGE_CLICK"); accept.putExtra("reqId", extras.getString("reqId")); accept.putExtra("answer", "1"); PendingIntent acceptIntent = PendingIntent.getActivity(this, 1, accept, PendingIntent.FLAG_CANCEL_CURRENT); this.sendBroadcast(accept);

工作正常.

推荐答案

我必须更改

PendingIntent.getActivity

PendingIntent.getBroadcast

更多推荐

通知操作按钮不会触发待定意图

本文发布于:2023-11-27 11:27:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   待定   按钮   操作   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!