【问题标题】:Is it OK to use the SERVER_API key on a client, and is it possible to send a GCM message to a device group without using the SERVER_API key?在客户端上使用 SERVER_API 密钥是否可以,是否可以在不使用 SERVER_API 密钥的情况下向设备组发送 GCM 消息?
【发布时间】:2015-12-16 22:04:50
【问题描述】:

我已经成功地向本地管理的设备组注册了我的 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 密钥,这被认为放在客户端上并不是一件好事。

我的问题是:在客户端使用 SERVER_API 密钥有问题吗?

第二:是否可以不使用SERVER_API密钥发送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.

【问题讨论】:

    标签: android google-cloud-messaging


    【解决方案1】:

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

    这个密钥是一个秘密,不会在你的二进制文件中被混淆。有人可以轻松下载您的 APK,运行 strings(或类似工具),然后开始代表您的应用发送 GCM 消息。

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

    【讨论】:

    • 那么就没有办法在不使用服务器密钥的情况下发送 GCM 消息,因为它需要服务器密钥来发送消息?
    • 是的,这是正确的。 Android 设备只能发送到服务器(使用 GCM Android API),然后服务器可以发送到其他设备。
    猜你喜欢
    • 2021-10-24
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多