새로운 Parse Android SDK에서 푸시 알림을 사용 중지하는 방법은 무엇인가요?Android 파싱 안함 푸시 알림
내 앱에서 사용 중지 알림을위한 환경 설정이 있습니다. 따라서 사용자가 환경 설정을 선택 해제하면 앱의 알림을 사용 중지 (푸시 서비스 종료)하고 싶습니다. 예를 들어, 이전 SDK에서는 PushService.setDefaultCallback (null)을 호출해야하며 푸시 서비스는 중지됩니다.
내 응용 프로그램 클래스에 푸시 알림을 구독하는 방법이 있습니다 : 내가 설정 변경을 수신하는 방법 내 환경 설정에
@Override public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, BuildConfig.PARSE_APP_ID, BuildConfig.PARSE_CLIENT_KEY);
// Register for Push Notifications ?
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
boolean notificationsEnabled =
sharedPref.getBoolean(SettingsFragment.PREF_KEY_ENABLE_NOTIFICATIONS, true);
if(notificationsEnabled){
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Timber.d("successfully subscribed to the broadcast channel.");
} else {
Timber.e(e, "failed to subscribe for push");
}
}
});
}
}
이를 단편화 :
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals(PREF_KEY_ENABLE_NOTIFICATIONS)){
boolean notificationsEnabled = sharedPreferences.getBoolean(PREF_KEY_ENABLE_NOTIFICATIONS, true);
if(notificationsEnabled){
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Timber.d("successfully subscribed to the broadcast channel.");
} else {
Timber.e(e, "failed to subscribe for push");
}
}
});
}
else {
ParsePush.unsubscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Timber.d("successfully un-subscribed from the broadcast channel.");
} else {
Timber.e(e, "failed to un-subscribe for push");
}
}
});
}
}
}
내 대답을 확인하십시오. –
@PsyDuck – Gustavo