通知操作按钮不会触发待定意图 [英] Notification action button does not fire pending intent
本文介绍了通知操作按钮不会触发待定意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从通知操作按钮向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
这篇关于通知操作按钮不会触发待定意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文