[英]Azure disable push notifications android
我將Android應用程序的推送通知系統從Urban Airship切換到Azure。 接收通知正常,但禁用通知則無效。 我的設置菜單中有一個按鈕,可以切換用戶是否收到推送通知。 當前,按鈕調用的方法如下所示:
public static void setPushEnabled( Context context, boolean isEnabled) {
if( isEnabled ) {
NotificationsManager.handleNotifications(context, SENDER_ID, MyPushHandler.class);
} else {
NotificationsManager.stopHandlingNotifications(context);
}
}
在stopHandlingNotifications
之后,該應用程序仍會收到推送通知。 然后,如果用戶重新打開推送通知, handleNotifications
再次調用handleNotifications
,並且對於從服務器發送的每一個通知,用戶都會收到2條通知。 這是NotificationsManager的文檔: http : //dl.windowsazure.com/androiddocs/com/microsoft/windowsazure/notifications/NotificationsManager.html
我在這里想念什么嗎? 有誰知道禁用Azure推送通知的其他方法嗎?
我所缺少的是MyPushHandler
類中的onUnregistered
處理程序,此代碼對其進行了修復:
@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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.