Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequiresApi(api = Build.VERSION_CODES.O)
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- String identifyDataType = remoteMessage.getData().get(getString(R.string.data_type));
- //SITUATION: Application is in foreground then only send priority notificaitons such as an admin notification
- Log.d(TAG, "Data type: data: " +identifyDataType);
- if(identifyDataType.equals(getString(R.string.data_type_admin_broadcast))){
- //build admin broadcast notification
- String title = remoteMessage.getData().get(getString(R.string.data_title));
- String senderId=remoteMessage.getData().get(getString(R.string.sender_of_message));
- String message = remoteMessage.getData().get(getString(R.string.data_message));
- Log.d(TAG,"TITL AND MESSG"+title+message);
- sendBroadcastNotification(title, message,senderId);
- }
- }
- @RequiresApi(api = Build.VERSION_CODES.O)
- private void sendBroadcastNotification(String title, String message, String senderId){
- Log.d(TAG, "sendBroadcastNotification: building a admin broadcast notification with "+title+" "+message);
- NotificationChannel mChannel=null;
- // Instantiate a Builder object.
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "default_channel_id");
- // Creates an Intent for the Activity
- Intent notifyIntent = new Intent(this, MainActivity.class);
- notifyIntent.putExtra("Id", "none");
- Log.d("messsagingService Title",title);
- notifyIntent.putExtra("Name", title.split(":")[1].trim());
- // Sets the Activity to start in a new, empty task
- notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- // Creates the PendingIntent
- PendingIntent notifyPendingIntent =
- PendingIntent.getActivity(
- this,
- 0,
- notifyIntent,
- PendingIntent.FLAG_UPDATE_CURRENT
- );
- NotificationManager mNotificationManager =
- (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- mChannel = new NotificationChannel("default_channel_id", getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
- // Configure the notification channel.
- mChannel.setDescription(message);
- mChannel.enableLights(true);
- mChannel.setLightColor(Color.RED);
- mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
- mNotificationManager.createNotificationChannel(mChannel);
- //add properties to the builder
- builder.setSmallIcon(R.drawable.icons1)
- .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
- R.drawable.icons1))
- .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
- .setContentTitle(title)
- .setContentText(message)
- .setColor(getResources().getColor(R.color.blue_btn_bg_color))
- .setAutoCancel(true)
- .setStyle(new NotificationCompat.BigTextStyle()
- .bigText(title).setSummaryText(message))
- .setNumber(mNumPendingMessages)
- .setOnlyAlertOnce(true);
- builder.setContentIntent(notifyPendingIntent);
- mNotificationManager.notify(BROADCAST_NOTIFICATION_ID, builder.build());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement