Guest User

Untitled

a guest
Oct 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. final int NOTIFY_ID = 1002;
  2. String aMessage="";
  3. String name = "my_package_channel";
  4. String id = "my_package_channel_1"; // The user-visible name of the channel.
  5. String description = "my_package_first_channel"; // The user-visible description of the channel.
  6.  
  7. Intent intent;
  8. PendingIntent pendingIntent;
  9. NotificationCompat.Builder builder;
  10.  
  11. if (notifManager == null) {
  12. notifManager =
  13. (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  14. }
  15.  
  16. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  17. int importance = NotificationManager.IMPORTANCE_HIGH;
  18. NotificationChannel mChannel = notifManager.getNotificationChannel(id);
  19. if (mChannel == null) {
  20. mChannel = new NotificationChannel(id, name, importance);
  21. mChannel.setDescription(description);
  22. notifManager.createNotificationChannel(mChannel);
  23. }
  24. builder = new NotificationCompat.Builder(this, id);
  25.  
  26. intent = new Intent(this, NotificationReturnSlot.class);
  27. pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
  28.  
  29. builder.setContentTitle(aMessage) // required
  30. .setSmallIcon(R.mipmap.ic_launcher)
  31. .setContentText(this.getString(R.string.app_name)) // required
  32. .setAutoCancel(false)
  33. .setContentIntent(pendingIntent)
  34. .setVibrate(new long[]{0L})
  35. ;
  36. } else {
  37.  
  38. builder = new NotificationCompat.Builder(this);
  39.  
  40. intent = new Intent(this, NotificationReturnSlot.class);
  41. pendingIntent = PendingIntent.getActivity(this, 1, intent, 0);
  42.  
  43. builder.setContentTitle(aMessage) // required
  44. .setSmallIcon(R.mipmap.ic_launcher)
  45. .setContentText(this.getString(R.string.app_name)) // required
  46. .setAutoCancel(false)
  47. .setContentIntent(pendingIntent)
  48. .setVibrate(new long[]{0L})
  49. .setPriority(Notification.PRIORITY_HIGH);
  50. }
  51. int mId = 1489;
  52. startForeground(mId, builder.build());
Add Comment
Please, Sign In to add comment