Отметьте следующие строки кода, которые помогут вам нажать кнопку уведомления о клике
Добавить приведенный ниже код в методе callNotification ()
Notification notification = null;
Intent skip = new Intent(mContext, NotificationActionService.class);
skip.setAction(101);//replace with your custom value
skip.putExtra("test", "test");
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(mContext, 12345, skip, PendingIntent.FLAG_UPDATE_CURRENT);
Intent drink = new Intent(mContext, NotificationActionService.class);//attach all keys starting with wzrk_ to your notification extras
drink.setAction(102);//replace with your custom value
PendingIntent pendingIntentNo = PendingIntent.getBroadcast(mContext, 123456, drink, PendingIntent.FLAG_UPDATE_CURRENT);
notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
.setSound(soundUri)
.setChannelId(channelId)
.addAction("your icon", "skip", pendingIntentYes) //Action Button 1, update the ic_launcher with a image present in your
.addAction("your icon", "dring",pendingIntentNo) // Action Button 2, maximum 3 allowed
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
.setContentText(message)
.build();
public class NotificationActionService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Bundle answerBundle = intent.getExtras();
switch (action){
case 101:
Intent intent1 = new Intent(context,MainActivity.class);
intent1.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
break;
case 102:
break;
}
NotificationUtils.clearNotifications(context);
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast(it);
}
}
Примечание : Не забудьте объявить в манифесте
<receiver android:name=".NotificationActionService" />