Parse.com 禁用推送通知通知 [英] Parse.com disable push notification notification

查看:19
本文介绍了Parse.com 禁用推送通知通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想处理推送通知而不在通知栏中显示它,这是 Parse.com 默认所做的.

I want to handle the push notification without showing it in the notification bar, what Parse.com does by default.

Parse.com 需要清单中的条目,因此我无法将其更改为我自己的 BroadcastReceiver,因为它不起作用.

Parse.com requires the entry in manifest, so I can't change it to my own BroadcastReceiver, because It will not work.

    <receiver android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND"
            android:priority="1">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="packagename" />
        </intent-filter>
    </receiver>

所以我所做的是为相同的 IntentFilter 创建第二个接收器,但具有更高的优先级.

So what I have done is creating the second receiver for the same IntentFilter, but with higher priority.

    <receiver android:name="packagename.ParseComPushReceiver"
        android:permission="com.google.android.c2dm.permission.SEND"
        android:priority="2">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="packagename" />
        </intent-filter>
    </receiver>

然后我尝试中止广播

@Override
public void onReceive(final Context context, final Intent intent) {
    abortBroadcast();
    // handle here
}

但不幸的是,我仍然在通知栏中看到收到通知"通知.

But unfortunately, it I still see the "Notification received" notification in the notification bar.

推荐答案

您实际上可以将自己的自定义广播接收器与 Parse 结合使用.它记录在推送指南此处.

You can actually use your own custom Broadcast Receiver with Parse. It's documented in the Push Guide here.

具体来说,替换:

    <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.example.MyCustomReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="com.example.UPDATE_STATUS" />
            <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>

并实现您自己的接收器:

And implement your own receiver:

public class MyCustomReceiver extends ParsePushBroadcastReceiver {
private static final String TAG = "MyCustomReceiver";

  @Override
  public void onReceive(Context context, Intent intent) {
    try {
      String action = intent.getAction();
      String channel = intent.getExtras().getString("com.parse.Channel");
      JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

      // Custom behavior goes here

    } catch (JSONException e) {
      Log.d(TAG, "JSONException: " + e.getMessage());
    }
  }
}

这篇关于Parse.com 禁用推送通知通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆