GCM here州的Android文档
数据参数中的键对值,它们可用作 这个意图中的额外内容,键是额外的名称。
private void handleMessage(Intent intent) {
// server sent 2 key-value pairs, score and time
String score = intent.getExtra("score");
String time = intent.getExtra("time");
// generates a system notification to display the score and time
}
但是intent.getExtra()方法不接受参数
public Bundle getExtras ()
Since: API Level 1
Retrieves a map of extended data from the intent.
Returns
the map of all extras previously added with putExtra(), or null if none have been added.
MyQuestion
如何在onMessage()
方法中从GCM消息中检索“字符串”?
P.S onMessage(Context context, Intent intent): Called when your server sends a message to GCM, and GCM delivers it to the device. If the message has a payload, its contents are available as extras in the intent.
答案 0 :(得分:10)
您应该使用:
intent.getExtras().getString("score");
intent.getExtras().getString("time");
注意类型,可以是:
intent.getExtras().getInt("myvar");
或其他一些类型。看看Bundle。