我正在将 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 推送通知的其他方法吗?
最佳答案
我缺少的是 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();
}
关于android - Azure禁用推送通知android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30401083/