【问题标题】:How to change the java code from GCM functionality to FCM functionality如何将 Java 代码从 GCM 功能更改为 FCM 功能
【发布时间】:2017-08-11 12:33:59
【问题描述】:
public class GcmIntentService extends FirebaseInstanceIdService {

    public GcmIntentService() {
        // super("GcmIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        String messageType = gcm.getMessageType(intent);
        if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            sendNotification(intent.getExtras());
        }

        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }

最初我在 GCM 中构建了一个没有任何错误的文件并将其附加到 firebase,但是当我在手机中运行它时它不起作用,那么如何将我的 java 代码从 GCM 更改为 FCM 以便它工作正确并按照火力基地工作。

【问题讨论】:

  • 如果你用谷歌搜索过这个,你会发现官方的 gcm->fcm 迁移指南

标签: java android firebase firebase-cloud-messaging


【解决方案1】:

official documentation 中可以找到关于从 GCM 迁移到现代 FCM 的答案。

流程如下:

  1. 将您的 GCM 项目作为 Firebase 项目导入
  2. 在应用级 build.gradle 中切换到 FCM

    compile "com.google.firebase:firebase-messaging:9.0.0"
    
  3. 移除 GCM 所需的权限
  4. 从应用清单中删除接收器
  5. 迁移您的侦听器服务
  6. 更新 Android 清单
  7. 更新您的 InstanceIDListenerService
  8. 删除注册
  9. 迁移您的 GcmListenerService
  10. 更新 Android 清单
  11. 更新您的 GcmListenerService
  12. 更新 GcmPubSub 的使用
  13. 更新服务器端点

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 2021-04-30
    • 2019-12-13
    • 2019-12-10
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多