android - 使用 GCM 的 Azure 推送通知

标签 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++;
            }
        }

我想知道如何取消注册之前标记的设备?

最佳答案

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

关于android - 使用 GCM 的 Azure 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27885686/

相关文章:

c# - 如何在windows azure中部署asp.net网站

c# - 以 Xamarin 形式实现视频通话,我有哪些选择?

java - 安卓测试: verify onClickListener using private anonymous class

java - 是否必须调用 AndroidThreeTen.init()?

android - 从 Activity 中调用 fragment 事件

适用于 1.7 的 Azure Powershell cmdlet,2012 年 6 月 : what's happened to Get-OperationStatus?

azure - Azure-Storage-Net 更改日志中 CoreCLR、PCL 和 WinRT 的重要性是什么

ios - Xamarin IOS 立即更改按钮颜色

Xamarin thrift pcl 实现

android - Android GridView 中的列大小