Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. private void handleNotification(RemoteMessage remoteMessage) {
  2. String notTitle = remoteMessage.getNotification().getTitle();
  3. String notBody = remoteMessage.getNotification().getBody();
  4.  
  5. Intent resultIntent = new Intent(this, HomeActivity.class);
  6. resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  7.  
  8. resultIntent.putExtra("pushNotClick", "yes");
  9. resultIntent.putExtra("pushNotHead", ""+notTitle);
  10.  
  11. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  12. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
  13. mBuilder.setSmallIcon(R.drawable.fb_icon);
  14. mBuilder.setColor(getResources().getColor(R.color.colorPrimary));
  15. mBuilder.setContentTitle(notBody)
  16. .setContentText(notTitle)
  17. .setAutoCancel(true)
  18. .setContentIntent(resultPendingIntent);
  19. NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
  20. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  21. int importance = NotificationManager.IMPORTANCE_HIGH;
  22. NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
  23. notificationChannel.enableLights(true);
  24. assert mNotificationManager != null;
  25. mBuilder.setSmallIcon(R.mipmap.icon_not);
  26. mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
  27. mNotificationManager.createNotificationChannel(notificationChannel);
  28. }
  29. assert mNotificationManager != null;
  30. mNotificationManager.notify((int) System.currentTimeMillis() /* Request Code */, mBuilder.build());
  31. }
  32.  
  33. String notState = getIntent().getStringExtra("pushNotClick");
  34. String notHead = getIntent().getStringExtra("pushNotHead");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement