【问题标题】:Parse.com disable push notification notificationParse.com 禁用推送通知通知
【发布时间】:2014-07-21 15:26:06
【问题描述】:

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

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

    <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 创建第二个接收器,但具有更高的优先级。

    <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
}

但不幸的是,我仍然在通知栏中看到“收到通知”通知。

【问题讨论】:

    标签: android push-notification parse-platform google-cloud-messaging


    【解决方案1】:

    您实际上可以将自己的自定义广播接收器与 Parse 一起使用。它记录在推送指南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>
    

    并实现你自己的接收器:

    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());
        }
      }
    }
    

    【讨论】:

    • 谢谢。我已多次阅读有关接收和处理推送的文档,但不知何故错过了这一点。
    • 是否有必要在这个实现中取消注册这个接收器。如果是这样,在哪里执行此操作?
    【解决方案2】:

    我不知道如何让这种方法适用于从 Web 控制台发送而不是从设备构造的推送,因此默认的“收到通知”消息仍然不断出现。

    对我有用的是将 android:exported="false" 添加到 parse.com 条目中,如下所示:

        <receiver
            android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND"
            android:exported="false">
            <intent-filter>
                <action android:name="com.example.DISABLE_PARSE_PUSH" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example" />
            </intent-filter>
        </receiver>
        <service android:name="com.parse.PushService" />
    

    这禁用了默认通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      相关资源
      最近更新 更多