0
我有一個報警設置爲每天觸發,我的問題是,我將有兩個按鈕在通知,延遲按鈕和我得到它按鈕。報警管理器對通知的響應
我如何做
代碼來設置報警:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 17);
calendar.set(Calendar.MINUTE, 38);
calendar.set(Calendar.SECOND, 00);
Intent intent = new Intent(getApplicationContext(), Notification_reciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
代碼在reciever:
Consulta_Tratamento consulta_tratamento =新Consulta_Tratamento();
String remedio = consulta_tratamento.getMedicamento(); String dose = consulta_tratamento.getDosagem();
PendingIntent pTomei = PendingIntent.getActivity(context, 0, new Intent(context, actMarcaCon.class),0);
PendingIntent pAdiar = PendingIntent.getActivity(context, 0, new Intent(context, actMarcaCon.class),0);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("MHS")
.setContentText(/*Colocar nome do usuário*/"Esta na Hora de Tomar Seu Remédio:" + remedio +
" /n dosagem:" + dose)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[]{100, 250, 100, 500})
.addAction(R.drawable.ic_adiar, "Adiar", pAdiar)
.addAction(R.drawable.ic_tomei, "Tomei", pTomei)
.setPriority(Notification.PRIORITY_HIGH);
if(intent!=null) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
notificationBuilder.setContentIntent(pendingIntent);
}
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
我的問題是,在添加操作方法,我只能通過和的PendingIntent,而不是方法,那麼怎樣才能使我的按鈕調用的方法,而不是意圖是什麼?