Guest User

Untitled

a guest
Oct 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  2. Notification notify=new Notification.Builder
  3. (getApplicationContext()).setContentTitle("BergEsapes").setContentText("Kindly Login Your Account").
  4. setContentTitle("User Register Succesfully").setSmallIcon(R.drawable.appicon).build();
  5.  
  6. notify.flags |= Notification.FLAG_AUTO_CANCEL;
  7. notif.notify(0, notify);
  8.  
  9. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  10. builder.setChannelId("YOUR_PACKAGE_NAME");
  11. }
  12. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  13. NotificationChannel channel = new NotificationChannel(
  14. "YOUR_PACKAGE_NAME",
  15. "YOUR_APP_NAME",
  16. NotificationManager.IMPORTANCE_DEFAULT
  17. );
  18. if (notificationManager != null) {
  19. notificationManager.createNotificationChannel(channel);
  20. }
  21. }
  22.  
  23. private void showNotification(String message){
  24.  
  25. NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"default")
  26. .setSmallIcon(android.R.drawable.ic_dialog_info)
  27. .setContentTitle("Notification Title")
  28. .setContentText(message)
  29. .setDefaults(NotificationCompat.DEFAULT_ALL)
  30. .setPriority(NotificationCompat.PRIORITY_HIGH)
  31. .setContentIntent(pendingIntent);
  32.  
  33. NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  34.  
  35. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  36. builder.setChannelId("YOUR_PACKAGE_NAME");
  37. }
  38. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  39. NotificationChannel channel = new NotificationChannel(
  40. "YOUR_PACKAGE_NAME",
  41. "YOUR_APP_NAME",
  42. NotificationManager.IMPORTANCE_DEFAULT
  43. );
  44. if (notificationManager != null) {
  45. notificationManager.createNotificationChannel(channel);
  46. }
  47. }
  48. notificationManager.notify(NOTIFICATION_ID,builder.build());
  49. }
Add Comment
Please, Sign In to add comment