首页 > 解决方案 > 如何迁移非常旧的 Android 应用 GCM->FCM,其中应用既是发送者又是接收者

问题描述

查看迁移文档,似乎这是在假设我的整个构建环境(gradle、插件、库)都是最新的。就我而言,它们已经 5 岁了,我不打算升级它们中的任何一个,因为我完全没有信心我不会最终陷入破碎的构建地狱。此外,这是一个我将在今年晚些时候用 PWA 替换的应用程序,因此迁移不需要面向未来或使用任何新功能。

因此,我正在寻找可能的最小步骤来迁移并防止应用程序崩溃。我想我在接收端有一个句柄,但我正在寻找有关注册和发送的建议。

我目前的代码是

// REGISTRATION
    gcm = GoogleCloudMessaging.getInstance(context);
    MyLog.d("[G152] about to register with gcm...");
    regid = gcm.register(SENDER_ID);
    msg = "Device registered, registration ID=" + regid;
// SENDING
    final String API_KEY = "AIzaAt-kduR...xDass";
    URL url = new URL("https://android.googleapis.com/gcm/send");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://android.googleapis.com/gcm/send");
    httppost.setHeader("Content-Type", "application/json");
    httppost.setHeader("Authorization", "key=" + API_KEY);
    StringEntity body = new StringEntity(new Gson().toJson(gcMessage));
    httppost.setEntity(body);
    HttpResponse response = httpclient.execute(httppost);

迁移需要做的最小更改是什么?

标签: firebasegoogle-cloud-platformgoogle-cloud-messagingfirebase-cloud-messaging

解决方案



推荐阅读