应用程序处于后台时,Android通知未展开

应用程序处于后台时,Android通知未展开,android,firebase,background,notifications,firebase-cloud-messaging,Android,Firebase,Background,Notifications,Firebase Cloud Messaging,我正在尝试使用FCM发送通知,它按预期工作,但我面临两种不同的行为,我想处理,因为我使用的是bigtextstyle和操作: 第一种情况:前台应用程序, onReceiveMessage按预期工作,通知显示正确 第二种情况:应用程序被杀死或处于后台, 文档说明onReceiveMessage事件不会处理消息,并且通知的布局不是bigtextstyle: 我试图找到一种显示所需布局的方法,但没有任何效果,他们说数据有效载荷是在发射器活动的目的之外交付的 因此,我想要的是在这两种情况下显示相同的通知

我正在尝试使用FCM发送通知,它按预期工作,但我面临两种不同的行为,我想处理,因为我使用的是bigtextstyle和操作:

第一种情况:前台应用程序, onReceiveMessage按预期工作,通知显示正确

第二种情况:应用程序被杀死或处于后台, 文档说明onReceiveMessage事件不会处理消息,并且通知的布局不是bigtextstyle:

我试图找到一种显示所需布局的方法,但没有任何效果,他们说数据有效载荷是在发射器活动的目的之外交付的

因此,我想要的是在这两种情况下显示相同的通知布局,因为有时我使用通知触发呼叫或在浏览器中打开链接,而不是打开应用程序本身

我从Firebase控制台发送消息,如图所示:

下面是通知的函数:

    private void notifyMe(RemoteMessage rm){
    String title = "";
    String body = "";
    String phone = "";
    String link = "";
    long time = System.currentTimeMillis();
    Intent iCall;
    PendingIntent pintCall = null;
    Intent notificationIntent = null;
    NotificationManager notificationManager;
    notificationManager =  (NotificationManager)FirebaseMessagingService.this.getSystemService(Context.NOTIFICATION_SERVICE);

    if (rm.getNotification() != null) {
        title = rm.getNotification().getTitle();
        body = rm.getNotification().getBody();
    }

    if (rm.getData().size() > 0) {
        phone = rm.getData().get("phone");
        link = rm.getData().get("link");

        if(link.contains("http://")){
            notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
        }else{
            notificationIntent = new Intent(FirebaseMessagingService.this, MainActivity.class);
        }

        if(phone.equalsIgnoreCase("")){
            iCall = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));
            pintCall = PendingIntent.getActivity(FirebaseMessagingService.this, 0, iCall, PendingIntent.FLAG_UPDATE_CURRENT);
        }

    }

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
    PendingIntent pint = PendingIntent.getActivity(FirebaseMessagingService.this, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setWhen(time)
            .setPriority(Notification.PRIORITY_MAX)
            .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
            .setContentIntent(pint);


    NotificationCompat.BigTextStyle bigtext =  new NotificationCompat.BigTextStyle();

    bigtext.setBigContentTitle(title);
    bigtext.bigText(body);

    mBuilder.setStyle(bigtext);

    if(!phone.equalsIgnoreCase("")){
        mBuilder.addAction(android.R.drawable.ic_menu_call, "Call me!", pintCall);
    }

    notificationManager.notify(0, mBuilder.build());
}
有人知道怎么做吗


谢谢。

Firebase通知控制台发送所谓的通知消息。当您的应用程序不在前台时,这些通知消息由系统本身处理,并以您看到的格式自动显示在通知栏中。当用户单击此通知时,应用程序将被激活

要确保消息始终传递到onReceiveMessage方法,请使用数据消息


有关详细说明,请参阅。

您的意思是我必须构建自己的服务器并管理注册和发送?目前只能通过Firebase云消息发送数据消息,而不能通过Firebase通知发送数据消息。FCM要求您的代码指定您的服务器密钥,正如名称所提示的,该密钥只应用于服务器上的受信任进程。Frank,我需要与我的服务器人员交谈,但我确信我们总是发送数据消息类型。当我的应用程序在后台时,我的挂起意图似乎都被忽略,通知对象打开进入我的启动程序活动。此外,它使用我的全彩图标,我在onReceive中专门将其设置为灰度。一些论坛帖子说这是firebase的一个bug,但你认为有一种方法可以解决它,只需设置一个“数据消息”类型?你是如何解决的?