android - 在客户端上使用 SERVER API key 是否可以,是否可以在不使用 SERVER API key 的情况下向设备组发送 GCM 消息?

标签 android google-cloud-messaging

我已成功向本地管理的设备组注册我的 Android 应用程序,如下所述:Google Cloud Messaging (GCM) with local device groups on Android gives HTTP Error code 401 .

这工作正常,我可以按照此处的指南将 GCM 消息从 Android 发送到 Android:https://developers.google.com/cloud-messaging/downstream .

但是,这使用了 SERVER_API key ,据说将其放在客户端上并不是一件好事。

我的问题是:在客户端使用 SERVER_API key 是否有问题?

其次:是否可以在不使用 SERVER_API key 的情况下发送 GCM 消息?

我尝试将从设备组注册收到的 notification_key 传递给此方法,但没有任何结果:

private void sendMessage2(String recipient) throws IOException {
    Log.i(TAG, "Sending message to " + recipient);
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    AtomicInteger msgId = new AtomicInteger();
    String id = Integer.toString(msgId.incrementAndGet());
    Bundle data = new Bundle();
    data.putString("hello", "world");
    gcm.send(recipient, id, data);
    Log.i(TAG, "Successfully sent message to " + recipient);
}

// recipient is the notification_key of the device group.

最佳答案

不要在您的客户端上使用 SERVER_API key !

此 key 是 secret 的,不会在您的二进制文件中进行混淆处理。有人可以轻松下载您的 APK,运行 strings(或类似工具),然后代表您的应用程序开始发送 GCM 消息。

如果你想做 Android <--> Android 消息传递,你实际上需要做 Android <--> Server <--> Android。

关于android - 在客户端上使用 SERVER API key 是否可以,是否可以在不使用 SERVER API key 的情况下向设备组发送 GCM 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34322968/

相关文章:

java - android一键下多个事件

android - 为什么我的异常处理程序不会捕获 Android SQLite 插入错误?

android - 在 android 中写入现有 JSON 文件时遇到问题

java - 将 json 对象添加到 Java HttpGet 请求到 C# WebApi

java - 应用程序未运行时的移动后端启动器通知

android - Activity 作为应用程序安装

android - Firebase 云消息传递设备 ID : multiple user in same app in same device

android - 通知振动,屏幕锁定时的声音

android - GCM - 一个注册 ID 有效,但因多个注册 ID 而失败

android - Android 推送通知的 FCM 限制?