当我通过Firebase Web界面向我的Android设备发送通知时,通知不会从状态栏上弹出。如果我想查看通知,必须向下滑动。即使在Web界面中将优先级设置为“高”,仍会发生这种情况。为什么会这样?
如果通知在应用程序打开时到达,则这不是问题,因为我可以在我的FirebaseMessagingService类中自己设置优先级。
如果通知在应用程序打开时到达,则这不是问题,因为我可以在我的FirebaseMessagingService类中自己设置优先级。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
sendNotification("Message Body");
}
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, SubscribedActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_push_notification)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setColor(ContextCompat.getColor(this, R.color.color_accent))
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}