我試圖接收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