我试图接收Android GCM推送通知,但.setContentTitle()
不起作用,默认情况下它只在标题上显示“通知”。FirebaseMessagingService`builder.setContentTitle()`不工作
这里是FcmMessagingService.java
public class FCMMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
Intent intent = new Intent(this,MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("FCM Notification");
builder.setContentText(message);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setAutoCancel(true);
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
super.onMessageReceived(remoteMessage);
}
}
您从消息中提取'title'但不要用它来建立通知。而是将通知标题设置为“FCM通知”。你想要通知的标题是什么? –
之前我已经'标题'设置为'builder.setContentTitle()',但我稀释这可能与我的'标题'问题,然后只是为了测试我设置“FCM通知”,但它是一样的。这只是为了确保我的'标题'是好的。谢谢。 – RxNReza