我已按照以下说明成功在本地管理的设备组中注册了我的Android应用:在Android上具有本地设备组的Google Cloud Messaging(GCM)给出了HTTP错误代码401。
这可以正常工作,并且我可以按照以下指南从Android向Android发送GCM消息: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 <-> Server <-> Android。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句