我为奥利奥创建了高度重视的频道。我从Oreo的Firebase控制台在前台收到通知,但在后台(当应用程序从RAM中被杀死时)没有收到通知。 在奥利奥以下,一切正常...
//fcm onMessage
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
Intent intent=new Intent(this,HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
final String title=remoteMessage.getData().get("title");
final String msg=remoteMessage.getData().get("body");
if( title!=null && msg!=null){
final Notification not = new NotificationCompat.Builder(this, CHANNEL_WELCOME)
.setContentTitle(title)
.setContentText(msg)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setSmallIcon(R.mipmap.ic_logo_final)
.setContentIntent(pendingIntent)
.build();
NotificationManagerCompat compat = NotificationManagerCompat.from(getApplicationContext());
compat.notify(33333, not);
}
}
答案 0 :(得分:0)
有两种类型的通知 1-通知消息,有时被称为“显示消息”。这些由FCM SDK自动处理。 2-数据消息,由客户端应用处理 您需要同时处理 @Override 公共无效onMessageReceived(RemoteMessage remoteMessage){
Log.d(TAG, "FROM:" + remoteMessage.getFrom());
//Check if the message contains data
if (remoteMessage.getData().size() > 0) {
} //如果(remoteMessage.getNotification()!= null){ // Log.d(TAG,“ Mesage body:” + remoteMessage.getNotification()。getBody()); }