2015-01-07 7 views
1

새로운 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"); 
        } 
       } 
      }); 
     } 
    } 
} 
+0

내 대답을 확인하십시오. –

+0

@PsyDuck – Gustavo

답변

4

/수신기를 비활성화하는 것은 도움이되지 않습니다. 이상하게도, 다시 시작한 후에 앱은 푸시를받을 수 없습니다. 내가 도달 한 가장 좋은 방법은 다음과 같습니다.

public class Receiver extends ParsePushBroadcastReceiver { 

    @Override 
    protected void onPushOpen(Context context, Intent intent) {...} 

    @Override 
    protected void onPushReceive(Context context, Intent intent) { 
     if (Esperandro.getPreferences(Prefs.class, context).show_notifications()) { //your shared preferences 
      super.onPushReceive(context, intent); 
     } 
    } 
} 
1

단순히 Parse.com로 이동 응용 프로그램의 설정 페이지를 엽니 다. 그런 다음 'Push'탭을 열고 'Client push enabled?'를 토글하십시오.

More Info Here.는 명확성을 위해 이미지를 참조하십시오 : 사용

enter image description here

+0

위의 질문에 코드 예제를 추가했습니다. 그 코드는 작동하지 않습니다. – Gustavo

+0

어떻게 작동하지 않습니까? 푸시를 비활성화하려면이 방법을 사용하십시오. –

+0

ParsePush.subscribeInBackground ("")를 호출하여 브로드 캐스트 채널을 구독 한 다음 클라이언트에서 설정을 적용하고 나중에 ParsePush.unsubscribeInBackground ("")를 호출하면 향후 알림을받지 못하게됩니다. – Gustavo

2

"기본"채널을 구독하는 것이 훨씬 쉽습니다. 그런 다음 푸시 알림을 사용 중지하면 채널 목록에서 알림을 삭제할 수 있습니다. 푸시 알림을 실행하면 모든 사람이 아닌 실제 채널로 이동하는 것이 좋습니다.

ParseInstallation installation = ParseInstallation.getCurrentInstallation(); 
List<String> channels = PushNotificationManger.getDefaultChannels(); 
installation.put("channels", channels); 
installation.saveInBackground();