Parse Android SDK1.8+でPush通知を無視する
Push通知をON/OFFにしたい。それをParseでするのに以前はPushService.setDefaultPushCallback
でnull
を渡すことで実現していましたが、ひさしぶりにParseを使ってみるとPushService.setDefaultPushCallback
がdeprecatedになっていたので代替の方法を探しました。
環境は次のとおり。
- Parse Android SDK1.8+
- gradle 2.2.1
ググって見つかったsubscribe/unsubscribe
を使ってchannel指定する方法だと、everyoneに配信したときに通知がでてしまう。ここのオペレーションは変えたくない。
そこで、Push通知を受け取るReceiverを継承してごにょごにょする方法を試したところ上手く行きました。
public class CustomReceiver extends ParsePushBroadcastReceiver { private static final String TAG = "CustomReceiver"; @Override public void onReceive(Context context, Intent intent) { Setting setting = ((AnyApplication)context.getApplicationContext()).getSetting(); if( setting.isEnabledReceiveNotification() ) { super.onReceive(context, intent); } else { abortBroadcast(); } } }
<receiver android:name="${applicationId}.CustomReceiver" 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>