Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void displayNotification(RemoteMessage.Notification notification) {
- Random rnd = new Random();
- Random rnd2 = new Random();
- int r = rnd.nextInt();
- int r2 = rnd2.nextInt();
- int id = (r * r2)+r;
- NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- String NOTIFICATION_CHANNEL_ID = "102356";
- Intent intent = new Intent(this, MainActivity.class); //Set the activity
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);
- Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- @SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_MAX);
- notificationChannel.setDescription("Channel description");
- notificationChannel.enableLights(true);
- notificationChannel.setLightColor(Color.RED);
- notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
- notificationChannel.enableVibration(true);
- notificationManager.createNotificationChannel(notificationChannel);
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
- notificationBuilder.setAutoCancel(true)
- .setDefaults(Notification.DEFAULT_ALL)
- .setWhen(System.currentTimeMillis())
- .setSmallIcon(R.drawable.myicon)
- .setTicker("ApptojoBusiness pr the name of the app")
- .setContentIntent(pendingIntent)
- .setContentTitle(notification.getTitle())
- .setContentText(notification.getBody())
- .setContentInfo(notification.getBody());
- notificationManager.notify(id, notificationBuilder.build());
- }else{
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
- .setSmallIcon(R.drawable.myicon)
- .setContentTitle(notification.getTitle())
- .setContentText(notification.getBody())
- .setAutoCancel(true)
- .setSound(defaultSoundUri)
- .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
- .setContentIntent(pendingIntent);
- NotificationManager notificationManager2 = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager2.notify(id, notificationBuilder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement