I have implemented firebase successfully. The only thing I am not able to achieve is NotificationCompat.PRIORITY_HIGH. Its working when the app is in foreground. In my PHP code I have added priority and its value to high. Though it seems to be useless for android. In my ios app priority high is working. I am not able to figure out how this can be done. Just for your Info : I am aware of payload data and notifications. :) Thank you.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
Bitmap bitmap;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
//It is optional
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Title: " + remoteMessage.getNotification().getTitle());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
String imageUrl = remoteMessage.getData().get("image");
bitmap = getBitmapfromUrl(imageUrl);
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
}
private void sendNotification(String messageBody, String title) {
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Log.e("inside notification", "method");
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_bicycle)
.setColor(getResources().getColor(R.color.ColorPrimary))
.setContentTitle(title)
.setContentText(messageBody)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
if (Build.VERSION.SDK_INT >= 19) {
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody));
notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(img))
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Random rn = new Random();
int result = rn.nextInt(100 + 1);
notificationManager.notify(result, notificationBuilder.build());
}