Firebase通知中断了服务器通知 [英] Firebase Notification broke server notifications

查看:121
本文介绍了Firebase通知中断了服务器通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android应用程序中从GCM切换到了FCM。但我没有触及代码的服务器部分,因为据说我不需要。但现在,当服务器发送通知时,我的设备不再看到它。所以我误解了以下内容?



https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints


不需要更新这些端点,因为Google将
继续支持现有的GCM端点。



<

 <! - 用于通知 - > 
<! - <使用权限android:name =android.permission.WAKE_LOCK/> - >
<! - < uses-permission android:name =com.google.android.c2dm.permission.RECEIVE/> - >
<! - < uses-permission android:name =com.business.myapp.android.permission.C2D_MESSAGE/> - >

...

< application ...>

...
<! - START GCM SECTION - >
<! - < receiver - >
<! - android:name =com.google.android.gms.gcm.GcmReceiver - >
<! - android:exported =true - >
<! - android:permission =com.google.android.c2dm.permission.SEND> - >
<! - <意向过滤器> - >
<! - < action android:name =com.google.android.c2dm.intent.RECEIVE/> - >

<! - < category android:name =com.business.myapp/> - >
<! - < / intent-filter> - >
<! - < / receiver> - >

< service
android:name =。data.service.notification.BusinessGcmListenerService
android:exported =false>
< intent-filter>
< action android:name =com.google.firebase.MESSAGING_EVENT/>
< / intent-filter>
< / service>
< service
android:name =。data.service.notification.BusinessInstanceIDListenerService>
< intent-filter>
< action android:name =com.google.firebase.INSTANCE_ID_EVENT/>
< / intent-filter>
< / service>
< service
android:name =。data.service.notification.RegistrationIntentService
android:exported =false>
< intent-filter>
< action android:name =com.google.android.c2dm.intent.RECEIVE/>
< / intent-filter>
< / service>
<! - END GCM SECTION - >

请注意,当我从Firebase控制台发送通知时,如果应用程序处于前台,它通过 onMessageReceived ;否则,我只是在状态栏中收到通知。基本上我按照提供的链接上的说明。



这是onTokenRefresh

  @Override 
public void onTokenRefresh(){
Intent intent = new Intent(this,RegistrationIntentService.class);
startService(intent); //将令牌发送到服务器的意图服务

code $ < h2_lin>解决方案

你更改你的应用程序的根/ app的json-service.json?

I have made the switch from GCM to FCM in my android app. But I have not touched the server portion of the code since supposedly I don’t have to. But now, when server sends a notification, my device is no longer seeing it. So did I misunderstand the following?

https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints

Updating these endpoints is not strictly required, as Google will continue to support the existing GCM endpoints.

MANIFEST

<!-- for notifications -->
    <!--<uses-permission android:name="android.permission.WAKE_LOCK"/>-->
    <!--<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>-->
    <!--<uses-permission android:name="com.business.myapp.android.permission.C2D_MESSAGE"/>-->

…

<application …>

…
<!-- START GCM SECTION -->
        <!--<receiver-->
            <!--android:name="com.google.android.gms.gcm.GcmReceiver"-->
            <!--android:exported="true"-->
            <!--android:permission="com.google.android.c2dm.permission.SEND">-->
            <!--<intent-filter>-->
                <!--<action android:name="com.google.android.c2dm.intent.RECEIVE"/>-->

                <!--<category android:name="com.business.myapp"/>-->
            <!--</intent-filter>-->
        <!--</receiver>-->

        <service
            android:name=".data.service.notification.BusinessGcmListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name=".data.service.notification.BusinessInstanceIDListenerService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
        <service
            android:name=".data.service.notification.RegistrationIntentService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            </intent-filter>
        </service>
        <!-- END GCM SECTION -->

Note that when I send notification from the Firebase Console it comes through: if the app is in the foreground, it goes through onMessageReceived; otherwise, I just get a notification in status bar. Basically I follow the instructions on the link provided.

Here is onTokenRefresh

@Override
public void onTokenRefresh() {
    Intent intent = new Intent(this, RegistrationIntentService.class);
    startService(intent);//intent service to send token to my server
}

解决方案

Do you change your json-service.json of on root /app of on application ?

这篇关于Firebase通知中断了服务器通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆