我想做这个问题中描述的事情,但要发送到Android客户端。Android客户端如何正确处理alert
对象中的loc-key
、loc-args
和action-loc-key
参数?
云代码:
Parse.Push.send({
where: pushQuery,
data: {
title: title,
alert: {
"loc-key":"msg",
"loc-args":["John"],
"action-loc-key":"rsp"
},
type: type
}
}
安卓客户端如何正确处理这些密钥并本地化推送?我必须手动对Parse广播接收器进行子类化吗?
是的,您必须对解析广播接收器进行子类化
首先,在你的清单中声明一个接收者
<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();
}
}
}