我可以使用Parse成功发送带有以下数据的推送通知,但无法在我的自定义广播接收器中接收消息.按照Parse
Android通知指南:
https://parse.com/docs/push_guide#receiving/Android.任何帮助将不胜感激!
发送推送:
ParseQuery<ParseInstallation> userQuery = ParseInstallation.getQuery(); userQuery.whereContainedIn("user",arg0); JSONObject data= null; try { data = new JSONObject("{\"title\" : \"Hush!\"," + "\"intent\" : \"ChatwindowActivity\"," + "\"action\" : \"com.hush.UPDATE_STATUS\"," + "\"chatId\" :" + getobjectId() + "}"); } catch (JSONException e) { e.printstacktrace(); } ParsePush push = new ParsePush(); push.setQuery(userQuery); push.setData(data); push.setMessage("One of your friends wants to chat..."); push.sendInBackground();
AndroidManifest设置:
<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="com.hush.HushPushReceiver" android:exported="false"> <intent-filter> <action android:name="com.hush.UPDATE_STATUS" /> </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.hush" /> </intent-filter> </receiver>
自定义推送接收器:
package com.hush; import java.util.Iterator; import org.json.JSONException; import org.json.JSONObject; import android.content.broadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.Toast; import com.parse.ParseAnalytics; public class HushPushReceiver extends broadcastReceiver { private static final String TAG = "DEBUG"; @Override public void onReceive(Context context,Intent intent) { Toast.makeText(context,"Push received!!!!.",Toast.LENGTH_LONG).show(); ParseAnalytics.trackAppOpened(intent); try { String action = intent.getAction(); String channel = intent.getExtras().getString("com.parse.Channel"); JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.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)); } } catch (JSONException e) { Log.d(TAG,"JSONException: " + e.getMessage()); }
}
}
解决方法
基于此推送通知演示了解它!
https://github.com/ahiraz/pushNotificationDemo
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。