AWS SNS正在向
发送有效负载@Override
public void onMessageReceived(final String from, final Bundle data) {
String message = getMessage(data);
Log.d(LOG_TAG, "Message: " + message);
int timeToLive = data.getInt("time_to_live");
Log.d(LOG_TAG, "time_to_live: " + timeToLive);
String text = data.getString("text");
Log.d(LOG_TAG, "Text: " + text);
消息采用
的形式PushListenerService: Message: {
"condition": "normal”,
"priority" : "normal",
"time_to_live" : 0,
"notification" : {
"body" : “random gibberish”,
"title" : "TEST TITLE”,
"icon" : “ic_launcher”
},
"data" : {
“GeoHash” : 1,
"text" : "TEST TEXT”
}
}
D/PushListenerService: time_to_live: 0
D/PushListenerService: Text: null
如何从中提取数据?我希望PushListener返回Text:TEST TEXT。我可以查询类似于查询json的包吗?正则表达式?
getMessage方法:
public static String getMessage(Bundle data) {
return data.containsKey("default") ? data.getString("default") : data.getString(
"message", "");
}
答案 0 :(得分:1)
你不能做这样的事情:
Bundle payload = data.getBundle("data");
String text = payload.getString("text");