I want that when I click "yes", a function called resetTimer will be called. How can I do that?
The code for the notification:
private void notificada() {
Intent yes = new Intent(ctx, TimerAppSaude.class);
yes.putExtra("yes", true);
yes.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent1 = PendingIntent.getBroadcast(ctx, 0, yes, PendingIntent.FLAG_ONE_SHOT);
Intent no = new Intent(ctx, TimerAppSaude.class);
no.putExtra("no", false);
no.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(ctx, 1, no, PendingIntent.FLAG_ONE_SHOT);
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("myCh", "MyChannel", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = ctx.getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, "myCh").setSmallIcon(R.drawable.ic_sms_notification)
.setContentTitle("Notificação")
.setContentText(nome)
.setSound(uri)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.addAction(R.drawable.ic_launcher_foreground, "yes", pendingIntent1)
.addAction(R.drawable.ic_launcher_foreground, "no", pendingIntent2);
notification = builder.build();
notificationManagerCompat = NotificationManagerCompat.from(ctx);
notificationManagerCompat.notify(1, notification);
}
CodePudding user response:
