我试图通过解析发送有针对性的通知,但它不起作用。我使用此代码接收
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
// set the current user id
installation.put("device_id", id.getText().toString());
installation.saveInBackground();
和这一个发送
ParseQuery query = ParseInstallation.getQuery();
// id is EditText to write the id of the targeted user manually
query.whereEqualTo("device_id", id.getText().toString());
ParsePush push = new ParsePush();
push.sendMessageInBackground("Hello", query);
我也试过
push.setQuery(query);
push.setMessage("Hello");
push.sendInBackground();
清单包含了其快速启动中所解析的所有内容 权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.test.singleuserpush.permission.C2D_MESSAGE" />
<uses-permission android:name="com.test.singleuserpush.permission.C2D_MESSAGE" />
服务和接收者
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
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>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.test.singleuserpush" />
</intent-filter>
</receiver>
这些都没有,有什么建议吗?
答案 0 :(得分:0)
使用push.setData
代替message
JSONObject data;
data = new JSONObject("{\"userName\": "+
"\""+"MyUserName"+"\""+
",\"profilePic\": "+
"\""+""+"\"}");
Log.e("Uber User customdata", data.toString());
JSONObject obj =new JSONObject();
obj.put("alert","New Alert Message");
obj.put("action","com.android.myappname");
obj.put("customdata",data); //send json
ParsePush push = new ParsePush();
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
答案 1 :(得分:0)
我通过在App设置中启用客户端推送,推送,启用客户端推送来解决问题。