2015-05-22 50 views
0

我將Android應用程序的推送通知系統從Urban Airship切換到Azure。接收通知工作正常,但禁用通知不起作用。我的設置菜單中有一個按鈕,可以切換用戶是否收到推送通知。目前,該按鈕調用該方法是這樣的:Azure禁用推送通知android

public static void setPushEnabled(Context context, boolean isEnabled) { 
    if(isEnabled) { 
     NotificationsManager.handleNotifications(context, SENDER_ID, MyPushHandler.class); 
    } else { 
     NotificationsManager.stopHandlingNotifications(context); 
    } 
} 

的應用程序仍然會收到推送通知stopHandlingNotifications被調用後。然後,如果用戶再次切換推送通知,則會再次調用handleNotifications,並且用戶從服務器發送的每個通知都會收到2個通知。以下是NotificationsManager的文檔:http://dl.windowsazure.com/androiddocs/com/microsoft/windowsazure/notifications/NotificationsManager.html

我在這裏錯過了什麼嗎?有誰知道任何其他方式來禁用Azure推送通知?

回答

0

我缺少的是在onUnregistered處理器在MyPushHandler類,這段代碼固定它:

@Override 
public void onUnregistered(Context context, final String gcmRegistrationId) { 
    super.onUnregistered(context, gcmRegistrationId); 

    new AsyncTask<Void, Void, Void>() { 
     protected Void doInBackground(Void... params) { 
      try { 
       mClient.getPush().unregisterAll(gcmRegistrationId); 
       return null; 
      } 
      catch(Exception e) { 

      } 
      return null; 
     } 
    }.execute(); 
}