我为奥利奥创建了高盗率的频道。我在奥利奥的火力基地控制台前台收到通知,但不在后台(当应用程序从 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);
}
}
有拖曳类型的通知 1-通知消息,有时被认为是"显示消息"。这些由 FCM SDK 自动处理。 2 - 数据消息,由客户端应用程序处理 您需要同时处理两者 @Override public void onMessageReceived(RemoteMessage remoteMessage( {
Log.d(TAG, "FROM:" + remoteMessage.getFrom());
//Check if the message contains data
if (remoteMessage.getData().size() > 0) {
} if (remoteMessage.getNotification(( != null( { Log.d(TAG, "Mesage body:" + remoteMessage.getNotification((.getBody(((; }