我在此网站https://developers.google.com/cloud-messaging/android/start上设置了Google云消息。在此过程结束时,我获得了一个用于Android项目的json文件和一个服务器密钥。当我在Google Api控制台中查看时,我也获得了一个Android Key,但与Google地图相比,我不必在Manifest中插入密钥。那么这个Android Key是什么?
答案 0 :(得分:0)
以下链接可能有所帮助 Google Developers
您获得的密钥是在您的服务器脚本(例如PHP)中使用,以将数据包发送到您的Android设备。
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key= YOUR_KEY_HERE
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
收到的消息应该在Android中处理,以生成推送通知,并可能将数据存储在内部数据库中。
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
// Handle received message here.
}
有关详细实现,请参阅本教程。 GCM Implementation.