Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void handleNotification(RemoteMessage remoteMessage) {
- String notTitle = remoteMessage.getNotification().getTitle();
- String notBody = remoteMessage.getNotification().getBody();
- Intent resultIntent = new Intent(this, HomeActivity.class);
- resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- resultIntent.putExtra("pushNotClick", "yes");
- resultIntent.putExtra("pushNotHead", ""+notTitle);
- PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
- mBuilder.setSmallIcon(R.drawable.fb_icon);
- mBuilder.setColor(getResources().getColor(R.color.colorPrimary));
- mBuilder.setContentTitle(notBody)
- .setContentText(notTitle)
- .setAutoCancel(true)
- .setContentIntent(resultPendingIntent);
- NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- int importance = NotificationManager.IMPORTANCE_HIGH;
- NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
- notificationChannel.enableLights(true);
- assert mNotificationManager != null;
- mBuilder.setSmallIcon(R.mipmap.icon_not);
- mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
- mNotificationManager.createNotificationChannel(notificationChannel);
- }
- assert mNotificationManager != null;
- mNotificationManager.notify((int) System.currentTimeMillis() /* Request Code */, mBuilder.build());
- }
- String notState = getIntent().getStringExtra("pushNotClick");
- String notHead = getIntent().getStringExtra("pushNotHead");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement