【问题标题】:Azure disable push notifications androidAzure禁用推送通知android
【发布时间】:2015-05-22 15:54:44
【问题描述】:

我正在将我的 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 将再次被调用,并且用户会收到来自服务器的每一个通知 2 个通知。这是 NotificationsManager 的文档:http://dl.windowsazure.com/androiddocs/com/microsoft/windowsazure/notifications/NotificationsManager.html

我在这里遗漏了什么吗?有谁知道禁用 Azure 推送通知的其他方法?

【问题讨论】:

    标签: android azure notifications push


    【解决方案1】:

    我缺少的是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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多