在通知中添加另一个具有不同功能的按钮

Adding another button with a different functionaity in notification

所以我有一个闹钟应用程序...当闹钟响起时,我会收到一个通知,上面有一个按钮可以关闭通知和闹钟声音...我想在通知上添加另一个按钮做同样的事情,但也会在 5 分钟后向接收器发送待定意图,以便闹钟响起(基本上我想在 5 分钟内暂停闹钟)但它只是不起作用..任何帮助 woou;非常感谢

这是我的接收器

public class AlarmReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent arg1) {

    Toast.makeText(context, ALARM RECEIVED, Toast.LENGTH_LONG).show();
 createNotification(context);
 }   
    public void createNotification(Context context){

    NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.mini)
                    .setContentTitle(context.getResources().getString(R.string.message_box_title))
                    .setContentText(context.getResources().getString(R.string.message2))
                    .setSubText(context.getResources().getString(R.string.message))
                    .setPriority(NotificationCompat.PRIORITY_HIGH);

    Intent intent = new Intent(context,MainActivity.class);
    PendingIntent pendingIntent=PendingIntent.getActivity(context,123,intent,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);


    Intent dismiss_intent=new Intent(context, MediaPlayingService.class);
    dismiss_intent.setAction(MediaPlayingService.ACTION_DISMISS);
 Intent dismissing_intent=new Intent(context, MediaPlayingService.class);
    dismissing_intent.setAction(MediaPlayingService.DISMISSING_ACTION);

    PendingIntent pending=PendingIntent.getService(context,123,dismiss_intent,PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pending2=PendingIntent.getService(context,123,dismissing_intent,PendingIntent.FLAG_UPDATE_CURRENT);

    PendingIntent pending=PendingIntent.getService(context,123,dismiss_intent,PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action= new NotificationCompat.Action(android.R.drawable.ic_lock_idle_alarm,
            "DISMISS",pending);
    mBuilder.addAction(action);
   NotificationCompat.Action action2= new NotificationCompat.Action(R.drawable.bell,"SNOOZE",pending);
    mBuilder.addAction(action2);


    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification=mBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(321,notification);
}

这是我的服务class

public class MediaPlayingService extends Service {
private MediaPlayer mp;
public static final String URI_BASE=MediaPlayingService.class.getName() + ".";
public static final String ACTION_DISMISS = URI_BASE + "ACTION_DISMISS";
 public static final String DISMISSING_ACTION = URI_BASE + "DISMISSING_ACTION";

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

public int onStartCommand(Intent intent, int flags, int startId) {


    String action = intent.getAction();
    if (ACTION_DISMISS.equals(action)) {
 dismiss();
 }else if(DISMISSING_ACTION.equals(action)){

        dismiss();
        snooze();
    }
           return START_NOT_STICKY;
    }


private void dismiss() {

    Intent intent=new Intent(this,MediaPlayingService.class);
    stopService(intent);

    intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent= PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmM= (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmM.cancel(pendingIntent);

    NotificationManager notiMana= (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
    notiMana.cancel(321);

}
  public void snooze(){ Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, 5*60*1000, pendingIntent);}

@Override
public void onDestroy() {
    super.onDestroy();
mp.stop();
}

}

我已经准备好我的贪睡功能我只需要知道如何为第二个按钮调用 dismiss() 和贪睡 () 而我只是不能...任何帮助将不胜感激

action2 应获得一个新的待定意图,并对其执行 SNOOZE 操作。