Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long when = System.currentTimeMillis();
- NotificationManager notificationManager = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
- // Create an explicit intent for an Activity in your app
- Intent intent = new Intent(context, NotificationActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra("id_notifica", id_notifica);
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
- Intent intent_si = new Intent(context, NotificationYesActivity.class);
- intent_si.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra("id_notifica", id_notifica);
- PendingIntent pendingIntent_si = PendingIntent.getActivity(context, 1, intent_si, 0);
- Intent intent_post = new Intent(context, NotificationPosticipaActivity.class);
- intent_post.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra("id_notifica", id_notifica);
- PendingIntent pendingIntent_post = PendingIntent.getActivity(context, 2, intent_post, 0);
- //Alarm Sound
- Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- String channelId = "Your_channel_id";
- NotificationChannel channel = null;
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- channel = new NotificationChannel(channelId,
- "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
- notificationManager.createNotificationChannel(channel);
- }
- NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
- context, channelId).setSmallIcon(R.drawable.logocartella)
- .setContentTitle("Promemoria farmaco")
- .setContentText("Hai preso " + id_farmaco + " alle " + notify_time + "?")
- .setSound(alarmSound)
- .setWhen(when)
- .addAction(0, "Si", pendingIntent_si) // #0
- .addAction(0, "Posticipa", pendingIntent_post)
- .setAutoCancel(true)
- .setWhen(when)
- .setContentIntent(pendingIntent)
- .setVibrate(new long[]{1000, 1000, 1000});
- notificationManager.notify(id_notifica, mNotifyBuilder.build());
- int notificationID = getIntent().getIntExtra("id_notifica", 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement