相关疑难解决方法(0)

Firebase推送通知更新数据库

我正在尝试通过新的Firebase推送通知服务向我的用户发送一些数据.

我正在使用"消息文本" - "dbupdate"添加一些"键值"自定义数据项,以检测它是更新消息还是我要向用户显示的正常推送通知.

在我的接收器中,我检查我是否有自定义数据并运行更新,如果为真.如果不是这种情况,我会通过短信显示正常通知.

它仅在我的应用程序打开时有效.如果应用程序关闭,则无论如何都会显示通知,而我的if检查甚至没有运行,

一些代码:

public class PushMessageService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Map<String,String> data = remoteMessage.getData();
        String link = data.get("link");
        String name = data.get("name");
        if (link!=null) {
            Log.d("link",link);
            Log.d("name",name);
            UpdateHelper.Go(this, link, name);
        }
        else {
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this)
                            .setSmallIcon(R.drawable.ic_shop_white_24dp)
                            .setAutoCancel(true)
                    .setContentTitle(remoteMessage.getNotification().getTitle())
                   .setContentText(remoteMessage.getNotification().getBody());
            NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(5, mBuilder.build());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里举例说明

为什么会这样?即使应用程序关闭,我该怎么做才能运行我的代码?

android firebase firebase-notifications

6
推荐指数
1
解决办法
1万
查看次数

我们可以只从 Firebase 通知控制台推送数据消息吗

我已经在我的项目中成功实施了 FCM。

是否有可能推只能从火力地堡控制台数据消息。

push-notification firebase firebase-cloud-messaging firebase-notifications

2
推荐指数
1
解决办法
3120
查看次数