【发布时间】: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