2017-03-03 57 views
1

我试图接收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); 
} 
} 

but getting like this

+0

您从消息中提取'title'但不要用它来建立通知。而是将通知标题设置为“FCM通知”。你想要通知的标题是什么? –

+0

之前我已经'标题'设置为'builder.setContentTitle()',但我稀释这可能与我的'标题'问题,然后只是为了测试我设置“FCM通知”,但它是一样的。这只是为了确保我的'标题'是好的。谢谢。 – RxNReza

回答

0

试用通知时,应用程序是在前台,而不是在背景相同或不同的结果

+0

你好,不一样它在前台应用程序中工作。该怎么办? – RxNReza

+0

是否调用onMessageReceived()方法检查它,或者如果您是从Firebase控制台进行测试,那么我们可以从它设置标题可能是重写您的通知标题 – Neha

+0

不,我使用PHP发送通知从我的应用程序服务器和我在清单中设置了服务 – RxNReza