使用GCM进行Azure推送通知

时间:2015-01-11 09:39:29

标签: android azure xamarin

如何从特定标记取消注册一个设备。 我发送带标签的通知。它运行良好。但即使我取消注册仍然会收到通知。

protected async void HandleRegistration(Context context, Intent intent)
        {


            string registrationId = intent.GetStringExtra("registration_id");
            string error = intent.GetStringExtra("error");
            string unregistration = intent.GetStringExtra("unregistered");


//Retriving string From The Memory

            ISharedPreferences preferences = PreferenceManager.GetDefaultSharedPreferences(context);
            string groupname = preferences.GetString ("GroupName","");


            var nMgr = (NotificationManager)GetSystemService (NotificationService);

            if (!String.IsNullOrEmpty (registrationId)) {
                NativeRegistration = await Hub.RegisterNativeAsync (registrationId,new[] {groupname.ToString()});

                var notificationNativeRegistration = new Notification (Resource.Drawable.notification, "Your Device Successfully Registered To "+groupname.ToString());
                var pendingIntentNativeRegistration = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0);

                notificationNativeRegistration.SetLatestEventInfo (this, "Device ID ", NativeRegistration.RegistrationId, pendingIntentNativeRegistration);
                nMgr.Notify (_messageId, notificationNativeRegistration);
                _messageId++;
            }
            else if (!String.IsNullOrEmpty (error)) {
                var notification = new Notification (Resource.Drawable.notification, "Gcm Registration Failed.");
                var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0);
                notification.SetLatestEventInfo (this, "Gcm Registration Failed", error, pendingIntent);
                nMgr.Notify (_messageId, notification);
                _messageId++;
            }
            else if (!String.IsNullOrEmpty (unregistration)) {
                if (NativeRegistration != null)
                    await Hub.UnregisterAsync (NativeRegistration);

                var notification = new Notification (Resource.Drawable.notification, "Unregistered successfully.");
                var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0);
                notification.SetLatestEventInfo (this, "MyIntentService", "Unregistered successfully.", pendingIntent);
                nMgr.Notify (_messageId, notification);
                _messageId++;
            }
        }

我想知道如何取消注册以前标记为?

的设备

1 个答案:

答案 0 :(得分:1)

您必须使用Microsoft Visual Studio服务总线资源管理器(Download)才能查看所有已注册的设备。您也可以从注册的设备列表中取消注册设备。