Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FirebaseMessagingService`builder.setContentTitle()`不工作_Android_Firebase - Fatal编程技术网

Android FirebaseMessagingService`builder.setContentTitle()`不工作

Android FirebaseMessagingService`builder.setContentTitle()`不工作,android,firebase,Android,Firebase,我正在尝试接收Android GCM推送通知,但.setContentTitle()不起作用,默认情况下,它只在标题上显示“通知” 这里是FcmMessagingService.java public class FCMMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { String titl

我正在尝试接收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);
}
}

当应用程序位于前台而非后台时尝试通知结果相同或不同

当应用程序位于前台而非后台时尝试通知结果相同或不同

您好,不一样当应用程序位于前台时它正在工作。怎么办?是onMessageReceived()吗方法称为check it,或者如果您正在firebase控制台测试它,那么我们可以从中设置标题,它可能会覆盖您的通知标题。不,我正在使用php从我的应用程序服务器发送通知,我已经在Manifests中设置了服务,因为当应用程序位于前台时,您的通知工作正常,这意味着您正在使用通知有效载荷尝试使用数据有效载荷您可以检查此
$fields=array('to'=>$key,'notification'=>array('title'=>$title,'body'=>$message))然后我尝试使用
$fields=array('to'=>$key,'data'=>array('title'=>$title,'body'=>$message))但samehello,不一样,当应用程序在前台时它会工作。怎么办?是onMessageReceived()吗方法称为check it,或者如果您正在firebase控制台测试它,那么我们可以从中设置标题,它可能会覆盖您的通知标题。不,我正在使用php从我的应用程序服务器发送通知,我已经在Manifests中设置了服务,因为当应用程序位于前台时,您的通知工作正常,这意味着您正在使用通知有效载荷尝试使用数据有效载荷您可以检查此
$fields=array('to'=>$key,'notification'=>array('title'=>$title,'body'=>$message))然后我尝试使用
$fields=array('to'=>$key,'data'=>array('title'=>$title,'body'=>$message))
但是sameYou从消息中提取
标题
,但不要使用它来生成通知。而是将通知标题设置为“FCM通知”。您希望通知的标题是什么?在我将
title
设置为
builder.setContentTitle()
之前,我想可能是我的
title
有问题,然后为了测试,我设置了“FCM通知”,但它是相同的。只是为了确保我的
标题
没有问题。谢谢。您可以从邮件中提取
标题
,但不用于生成通知。而是将通知标题设置为“FCM通知”。您希望通知的标题是什么?在我将
title
设置为
builder.setContentTitle()
之前,我想可能是我的
title
有问题,然后为了测试,我设置了“FCM通知”,但它是相同的。只是为了确保我的
标题
没有问题。非常感谢。