【发布时间】:2016-05-26 20:50:25
【问题描述】:
我已在我的 Android 应用中从 GCM 切换到 FCM。但是我没有接触过代码的服务器部分,因为据说我不必这样做。但是现在,当服务器发送通知时,我的设备不再看到它。那么是不是我误解了以下内容?
https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints
并非严格要求更新这些端点,因为 Google 会 继续支持现有的 GCM 端点。
清单
<!-- 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 -->
请注意,当我从 Firebase 控制台发送通知时,它会通过:如果应用程序在前台,它会通过 onMessageReceived;否则,我只会在状态栏中收到通知。基本上我按照提供的链接上的说明进行操作。
这里是 onTokenRefresh
@Override
public void onTokenRefresh() {
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);//intent service to send token to my server
}
【问题讨论】:
-
所以我按照该页面上的所有说明进行操作。除非服务器没有改变(另一个团队必须这样做);注释还说我不需要更改服务器。
-
您是否在其中创建了一个新的 Firebase 项目?还是从您现有的 Google 项目升级而来?
-
没有新项目。我只是使用我现有的项目。
-
您能否在客户端和清单的相关部分中包含您的 FCM 实现的 sn-p?问题可能就在那里。
-
我已经添加了清单数据和一些。我只是按照他们提供的步骤进行操作,请参阅链接developers.google.com/cloud-messaging/android/…
标签: android firebase google-cloud-messaging firebase-cloud-messaging