不工作的应用。如何从推送通知中获取解析数据?
我向Android设备发送了没有提醒的通知。
ParseQuery query = ParseInstallation.getQuery();
query.whereEqualTo(\"device_id\", \"1234567890\"); // device_id created in parse.com
ParsePush push = new ParsePush();
push.setQuery(query);
push.setData(data);
push.sendInBackground(); // i see this notification in parse.com
然后我写道:
public MyCustomReceiver myReceiver = new MyCustomReceiver();
myReceiver.onReceive(this, getIntent());
接收类:
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = \"MyCustomReceiver\";
@Override
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
String channel = intent.getExtras().getString(\"org.xxx.xxx.Channel\");
JSONObject json = new JSONObject(intent.getExtras().getString("org.xxx.xxx.Data"));
Log.d(TAG, \"got action \" + action + \" on channel \" + channel + \" with:\");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
Log.d(TAG, "..." + key + " => " + json.getString(key));
tv_n.setText(json.getString(key));
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
清单:
<receiver android:name="com.xxx.MyCustomReceiver" android:exported="false">
<intent-filter>
<action android:name="com.xxx.UPDATE_STATUS" />
</intent-filter>
</receiver>
答案 0 :(得分:0)
你有没有&#34;允许来自客户端的发送推送&#34;在推送标签中的项目设置中的parse.com上?
您是否将自定义接收器添加到清单?:
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="YOURPACKAJE.MyCustomReceiver "//its your this class should extends 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="YOURPACKAJE" />
</intent-filter>
</receiver>
还有更多信息,请参阅此问题和我的回答Getting Parse Push Notification in List view