标签: firebase-cloud-messaging

如何在Firebase中的后台应用时处理通知

这是我的清单

    <service android:name=".fcm.PshycoFirebaseMessagingServices">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name=".fcm.PshycoFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

当应用程序处于后台并且通知到达时,默认通知将会运行并且不会运行我的代码onMessageReceived.

这是我的onMessageReceived代码.如果我的应用程序在前台运行,而不是在后台应用程序时,则调用此方法.如何在应用程序处于后台时运行此代码?

// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO(developer): Handle FCM messages here.
    // If the application is in the foreground handle both data and notification messages here.
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

379
推荐指数
17
解决办法
31万
查看次数

211
推荐指数
7
解决办法
19万
查看次数

当应用程序在后台时,不会调用Firebase onMessageReceived

我正在使用Firebase,并在应用程序处于后台时测试从我的服务器向我的应用发送通知.通知成功发送,甚至出现在设备的通知中心,但是当通知出现或甚至我点击它时,我的FCMessagingService内的onMessageReceived方法永远不会被调用.

当我在我的应用程序位于前台时对此进行测试时,调用了onMessageReceived方法,一切正常.当应用程序在后台运行时会出现此问题.

这是预期的行为,还是有办法解决这个问题?

这是我的FBMessagingService:

import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class FBMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.i("PVL", "MESSAGE RECEIVED!!");
        if (remoteMessage.getNotification().getBody() != null) {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getNotification().getBody());
        } else {
            Log.i("PVL", "RECEIVED MESSAGE: " + remoteMessage.getData().get("message"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

201
推荐指数
15
解决办法
16万
查看次数

如何在不使用Firebase控制台的情况下发送Firebase云消息传递通知?

我开始使用新的Google服务进行通知Firebase Cloud Messaging.

感谢此代码https://github.com/firebase/quickstart-android/tree/master/messaging我能够将Firebase用户控制台的通知发送到我的Android设备.

是否有任何API或方式可以在不使用Firebase控制台的情况下发送通知?我的意思是,例如,PHP API或类似的东西,直接从我自己的服务器创建通知.

php api android firebase firebase-cloud-messaging

188
推荐指数
9
解决办法
27万
查看次数

不推荐使用FirebaseInstanceIdService

希望大家都知道这个类,用于在刷新通知令牌时刷新通知令牌,我们从这个类中获取刷新的令牌,来自以下方法.

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
}
Run Code Online (Sandbox Code Playgroud)

要使用它,我想实现FCM,我扩展了MyClass FirebaseInstanceIdService

但是,显示不推荐使用FirebaseInstanceIdService

有没有人知道这个?,我应该使用什么方法或类来代替这个来获取刷新令牌,因为这是不推荐使用的.

我正在使用 : implementation 'com.google.firebase:firebase-messaging:17.1.0'

我检查了相同的文件没有提到这个.:FCM设置文件


UPDATE

这个问题已被解决.

谷歌不赞成FirebaseInstanceService,

我问问题是找到方法,然后我知道我们可以从FirebaseMessagingService获取令牌,

和以前一样,当我问问题文档没有更新但是现在谷歌文档更新以获取更多信息时,请参阅此谷歌文档:FirebaseMessagingService

旧版自:FirebaseInstanceService(已弃用)

@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
}
Run Code Online (Sandbox Code Playgroud)

新来自:FirebaseMessagingService

@Override
public void onNewToken(String s) {
    super.onNewToken(s);
    Log.d("NEW_TOKEN",s);
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

android firebase firebase-cloud-messaging

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

在哪里可以找到适用于Firebase云消息传递的API KEY?

我试图弄清楚新版本的GCM或Firebase云消息传递是如何工作的,所以我将我的一个项目移动到新的Firebase控制台,如果我没有API KEY或者我想创建一个新的...其中我可以做吗?

firebase google-cloud-messaging firebase-cloud-messaging

129
推荐指数
4
解决办法
13万
查看次数

Firebase消息传递,在哪里获取服务器密钥?

Firebase允许我们通过提出POST请求通过我们自己的应用程序发送通知消息.

本教程向我们提供了如何发出此请求的说明.但是,Authorization标题中有字段,我必须放置自己的服务器密钥.

我可以在哪里获得此服务器密钥?没有这方面的说明.

firebase google-cloud-messaging firebase-cloud-messaging

124
推荐指数
9
解决办法
7万
查看次数

致命例外:Firebase-Messaging-Intent-Handle -- java.lang.NoClassDefFoundError

我没有在我的项目中使用任何 Firebase 或 Youtube 代码/库。然而最近,在 Android 预发布报告中,我看到了以下崩溃:

FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
Process: com.google.android.youtube, PID: 26820
java.lang.NoClassDefFoundError: aewt
    at aewu.b(PG:1)
    at duc.a(PG:230)
    at duc.get(PG:247)
    at aevw.b(PG:1)
    at dud.al(PG:5)
    at dud.aw(PG:4)
    at dud.bg(PG:8)
    at duc.a(PG:232)
    at duc.get(PG:247)
    at afke.a(PG:1)
    at aeri.b(PG:1)
    at dud.fv(PG:4)
    at duc.c(PG:269)
    at duc.get(PG:247)
    at amfk.a(PG:1)
    at eiu.K(PG:5)
    at dud.fV(PG:7)
    at duc.d(PG:334)
    at duc.get(PG:247)
    at com.google.android.apps.youtube.app.common.notification.FcmMessageListenerService.b(PG:1)
    at com.google.firebase.messaging.FirebaseMessagingService.g(PG:53)
    at avgp.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at usj.run(PG:2)
    at java.lang.Thread.run(Thread.java:831)
Run Code Online (Sandbox Code Playgroud)

这是另一个包含更多详细信息但问题不同的日志:

Process: com.google.android.youtube, PID: 16751
java.lang.NoClassDefFoundError: aewt
    
    [redacted]

    at com.google.android.apps.youtube.app.common.notification.FcmMessageListenerService.b(PG:1)
    at …
Run Code Online (Sandbox Code Playgroud)

java android firebase firebase-cloud-messaging prelaunch

121
推荐指数
2
解决办法
2万
查看次数

带有新Firebase云消息传递系统的通知图标

昨天谷歌在Google I/O上展示了基于新Firebase的新通知系统.我在Github上尝试了这个新的FCM(Firebase云消息传递)示例.

尽管我已声明了特定的drawable,但通知的图标始终是ic_launcher

为什么?以下是处理邮件的官方代码

public class AppFirebaseMessagingService extends FirebaseMessagingService {

    /**
     * Called when message is received.
     *
     * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
     */
    // [START receive_message]
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // If the application is in the foreground handle both data and notification messages here.
        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should …
Run Code Online (Sandbox Code Playgroud)

android push-notification googleio firebase firebase-cloud-messaging

118
推荐指数
5
解决办法
13万
查看次数

Firebase FCM强制onTokenRefresh()被调用

我正在将我的应用程序从GCM迁移到FCM.

当新用户安装我的应用程序时,onTokenRefresh()会自动调用该应用程序.问题是用户尚未登录(无用户ID).

如何onTokenRefresh()在用户登录后触发?

android firebase-cloud-messaging

107
推荐指数
2
解决办法
12万
查看次数