FirebaseMessagingService`builder.setContentTitle()`无效

时间:2017-03-03 16:43:19

标签: android firebase

我正在尝试接收Android GCM推送通知,但.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);
}
}

but getting like this

1 个答案:

答案 0 :(得分:0)

当应用处于前台而不是背景中的结果相同或不同时尝试通知