在客户端上使用 SERVER_API 键是否可以,是否可以在不使用 SERVER_API 键的情况下向设备组发送 GCM 消息?
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?
我已经成功地使用本地管理的设备组注册了我的 Android 应用程序,如下所述:。
这很好用,我可以按照此处的指南将 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.
不要在您的客户端上使用 SERVER_API 键!
此密钥是机密,不会在您的二进制文件中进行混淆处理。有人可以轻松下载您的 APK 运行 strings
(或类似工具),然后代表您的应用程序开始发送 GCM 消息。
如果你想做 Android <--> Android 消息传递,你实际上需要做 Android <--> 服务器 <--> Android.
我已经成功地使用本地管理的设备组注册了我的 Android 应用程序,如下所述:
这很好用,我可以按照此处的指南将 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.
不要在您的客户端上使用 SERVER_API 键!
此密钥是机密,不会在您的二进制文件中进行混淆处理。有人可以轻松下载您的 APK 运行 strings
(或类似工具),然后代表您的应用程序开始发送 GCM 消息。
如果你想做 Android <--> Android 消息传递,你实际上需要做 Android <--> 服务器 <--> Android.