Reputation: 545
I'm trying to send notification with additional action. I'm registering it in service:
IntentFilter filter = new IntentFilter();
filter.addAction(ACT_ACCEPT);
receiver = new notifReciever();
this.registerReceiver(receiver, filter);
My BroadcastReceiver:
public class notifReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("BR_Action", intent.getAction());
}
};
I'm sending it like this:
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(this, MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent contentIntentAccept = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(this, AppService.class).setAction(ACT_ACCEPT), PendingIntent.FLAG_CANCEL_CURRENT);
n = new Notification.Builder(getApplicationContext())
.setContentTitle("Test")
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setVibrate(pattern)
.addAction(R.drawable.ic_stat_accept, "Accept", contentIntentAccept)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setContentIntent(contentIntent).build();
But string with tag "BR_Action"
isn't added to the Log.
Upvotes: 0
Views: 43
Reputation: 3086
onReceive()
will only be called when you start the Intent and not just register it. Try using startActivity(new Intent(ACT_ACCEPT));
Upvotes: 1