我希望完全按照in this question描述的内容,但发送到Android客户端。 Android客户端如何正确处理loc-key
对象中的loc-args
,action-loc-key
和alert
参数?
云代码:
Parse.Push.send({
where: pushQuery,
data: {
title: title,
alert: {
"loc-key":"msg",
"loc-args":["John"],
"action-loc-key":"rsp"
},
type: type
}
}
Android客户端如何正确处理这些密钥并本地化推送?我是否必须手动子类化Parse广播接收器?
答案 0 :(得分:1)
是的,你必须继承Parse Broadcast接收器
首先,在清单中声明一个接收器
<receiver android:name="com.example.PushReceiver" android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
然后创建一个ParsePushBroadcastReceiver子类并覆盖onReceive方法。
public class PushReceiver extends ParsePushBroadcastReceiver{
@Override
public void onPushReceive(Context context, Intent intent) {
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
//This is where you get your values
JSONObject alertObject = json.getJSONObject("alert");
} catch (JSONException e) {
e.printStackTrace();
}
}
}