Guest User

Untitled

a guest
Mar 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. Intent intent = new Intent(this, HomeActivity.class);
  2. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  3. intent.putExtra(Constants.IS_FROM_NOTIFICATION, true);
  4. sendBroadcast(new Intent(Constants.REFRESH_STATUS));
  5.  
  6. PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
  7. PendingIntent.FLAG_ONE_SHOT);
  8.  
  9.  
  10. NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  11. NotificationCompat.Builder builder = null;
  12. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  13. int importance = NotificationManager.IMPORTANCE_DEFAULT;
  14.  
  15. NotificationChannel notificationChannel;
  16. // if (type.equals("1") || type.equals("2"))
  17. notificationChannel = new NotificationChannel("TripId", "Trip", importance);
  18. // else
  19. // notificationChannel = new NotificationChannel("ChatID", "Chat", importance);
  20.  
  21. notificationManager.createNotificationChannel(notificationChannel);
  22. builder = new NotificationCompat.Builder(getApplicationContext(), notificationChannel.getId());
  23. builder.setPriority(NotificationManager.IMPORTANCE_HIGH);
  24. } else {
  25. builder = new NotificationCompat.Builder(getApplicationContext());
  26. builder.setPriority(Notification.PRIORITY_MAX);
  27. }
  28. Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  29. builder = builder
  30. .setSmallIcon(R.mipmap.ic_notification_icon)
  31. // .setColor(ContextCompat.getColor(context, R.color.color))
  32. .setContentTitle(title)
  33. .setTicker(getString(R.string.app_name))
  34. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
  35. .setContentText(message)
  36. .setDefaults(Notification.DEFAULT_ALL)
  37. .setAutoCancel(true)
  38. .setContentIntent(pendingIntent);
  39.  
  40.  
  41. notificationManager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), builder.build());
Add Comment
Please, Sign In to add comment