【问题标题】:Not Receiving Parse Push Notifications on Android in Custom BroadcastReceiver在自定义 BroadcastReceiver 中未在 Android 上接收解析推送通知
【发布时间】:2014-03-01 18:20:35
【问题描述】:

我可以使用 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());
}

} }

【问题讨论】:

  • @N 看到你的博客,这太棒了。
  • 你能发布你的完整清单吗?

标签: android push-notification broadcastreceiver parse-platform


【解决方案1】:

根据这个推送通知演示弄清楚了! https://github.com/ahiraz/pushNotificationDemo

【讨论】:

  • 注意:要从上面的链接运行示例并查看它是如何工作的,您必须在解析仪表板中启用“客户端推送”通知。如果您想从应用程序发送通知并查看结果,您通常必须这样做
【解决方案2】:

在您正在使用的清单文件中

com.parse.GcmBroadcastReceiver

而不是使用您的自定义 broadcastreciver ,在您的情况下简单更改 > com.parse.GcmBroadcastReceiver 到

com.yourpackagename.IncomingReceiver

不要在模拟器中测试broadcastreciver,它不会工作,所以检查andorid设备

查看这个使用自定义广播接收器来解析推送通知的 repo https://github.com/srini-hashinc/IIYO/tree/master

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多