Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. long when = System.currentTimeMillis();
  2. NotificationManager notificationManager = (NotificationManager) context
  3. .getSystemService(Context.NOTIFICATION_SERVICE);
  4.  
  5. // Create an explicit intent for an Activity in your app
  6. Intent intent = new Intent(context, NotificationActivity.class);
  7. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
  8. .putExtra("id_notifica", id_notifica);
  9. PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
  10.  
  11. Intent intent_si = new Intent(context, NotificationYesActivity.class);
  12. intent_si.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
  13. .putExtra("id_notifica", id_notifica);
  14. PendingIntent pendingIntent_si = PendingIntent.getActivity(context, 1, intent_si, 0);
  15.  
  16. Intent intent_post = new Intent(context, NotificationPosticipaActivity.class);
  17. intent_post.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
  18. .putExtra("id_notifica", id_notifica);
  19. PendingIntent pendingIntent_post = PendingIntent.getActivity(context, 2, intent_post, 0);
  20.  
  21.  
  22. //Alarm Sound
  23. Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  24.  
  25. String channelId = "Your_channel_id";
  26. NotificationChannel channel = null;
  27. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  28. channel = new NotificationChannel(channelId,
  29. "Channel human readable title", NotificationManager.IMPORTANCE_DEFAULT);
  30. notificationManager.createNotificationChannel(channel);
  31.  
  32. }
  33.  
  34. NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
  35. context, channelId).setSmallIcon(R.drawable.logocartella)
  36. .setContentTitle("Promemoria farmaco")
  37. .setContentText("Hai preso " + id_farmaco + " alle " + notify_time + "?")
  38. .setSound(alarmSound)
  39. .setWhen(when)
  40. .addAction(0, "Si", pendingIntent_si) // #0
  41. .addAction(0, "Posticipa", pendingIntent_post)
  42. .setAutoCancel(true)
  43. .setWhen(when)
  44. .setContentIntent(pendingIntent)
  45. .setVibrate(new long[]{1000, 1000, 1000});
  46.  
  47. notificationManager.notify(id_notifica, mNotifyBuilder.build());
  48.  
  49. int notificationID = getIntent().getIntExtra("id_notifica", 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement