0

Я пытаюсь использовать лазурный пример толчка уведомления, как именно в этом примере https://github.com/xamarin/customer-success-samples/tree/master/samples/Xamarin.Android/AzurePushNotification.AndroidВсегда получить JsonReaderException при использовании Azure Push Notification в Xamarin Android

Я все шаги, я могу зарегистрировать устройство, возьмите регистрационный идентификатор с не проблема, но я всегда получаю эту ошибку JsonReaderException, когда пытаюсь отправить тестовое push-сообщение с лазурного портала. Любая помощь приветствуется, спасибо. тесты сообщения по умолчанию =

{ "данные": { "сообщение": "Уведомление Hub уведомление теста"}}

И ошибка

«Newtonsoft.Json. JsonReaderException: Ошибка чтения JObject из JsonReader Текущий JsonReader элемент не является объектом:.. Integer Путь ''»

И GcmServiceBase (так же, как образец)

namespace myapp.Droid 
{ 
    [BroadcastReceiver(Permission = Constants.PERMISSION_GCM_INTENTS)] 
    [IntentFilter(new string[] { Constants.INTENT_FROM_GCM_MESSAGE }, 
      Categories = new string[] { "myapp.Droid" })] 
    [IntentFilter(new string[] { Constants.INTENT_FROM_GCM_REGISTRATION_CALLBACK }, 
      Categories = new string[] { "myapp.Droid" })] 
    [IntentFilter(new string[] { Constants.INTENT_FROM_GCM_LIBRARY_RETRY }, 
      Categories = new string[] { "myapp.Droid" })] 
    public class GcmBroadcastReceiver : GcmBroadcastReceiverBase<GcmService> 
    { 
     public static string[] SENDER_IDS = { "my firebase sender id" }; 
     public const string HUB_NAME = "my hub namespace "; 
     public const string HUB_LISTEN_SECRET = "SharedAccessKey in the azure"; 
    } 

    [Service] 
    public class GcmService : GcmServiceBase 
    { 
     private static NotificationHub hub; 

     public GcmService() : base(GcmBroadcastReceiver.SENDER_IDS) { } 

     public static void Initialize(Context context) 
     { 
      var cs = ConnectionString.CreateUsingSharedAccessKeyWithListenAccess(
     new Java.Net.URI ("sb://" + GcmBroadcastReceiver.HUB_NAME(actually I write my hub namespace in here bcz when I write hub name ,it gives NotificationHubResourceNotFoundException error,so I write Hub Namespace) + "-ns.servicebus.windows.net/"), 
       GcmBroadcastReceiver.HUB_LISTEN_SECRET); 

      hub = new NotificationHub(GcmBroadcastReceiver.HUB_NAME, cs, context); 
     } 

     public static void Register(Context Context) 
     { 
      GcmClient.Register(Context, GcmBroadcastReceiver.SENDER_IDS); 
     } 

     protected override void OnRegistered(Context context, string registrationId) 
     { 
      //Receive registration Id for sending GCM Push Notifications to 
      if (hub != null) 
      { 
       var registration = hub.Register(registrationId, "TEST"); 
      } 
     } 

     protected override void OnUnRegistered(Context context, string registrationId) 
     { 
      if (hub != null) 
      { 
       hub.Unregister(); 
      } 
     } 

     protected override void OnMessage(Context context, Intent intent) 
     { 
      // Push Notification arrived 
      ShowLocalNotification(intent); 

      // Do additiona messaging here... 
     } 

     private void ShowLocalNotification(Intent intent) 
     { 
      //Push Notification arrived 
      if (intent != null || intent.Extras != null) 
      { 
       var msg = intent.Extras.GetString("message"); 

       msg = String.IsNullOrEmpty(msg) ? "No Message" : msg; 

       // Instantiate the builder and set notification elements: 
       Notification.Builder builder = new Notification.Builder(this) 
        .SetContentTitle("Push Notification Received") 
        .SetContentText(msg) 
        .SetDefaults(NotificationDefaults.Sound); 

       // Build the notification: 
       Notification notification = builder.Build(); 

       // Get the notification manager: 
       NotificationManager notificationManager = 
        GetSystemService(Context.NotificationService) as NotificationManager; 

       // Publish the notification: 
       const int notificationId = 0; 
       notificationManager.Notify(notificationId, notification); 
      } 
     } 

     protected override bool OnRecoverableError(Context context, string errorId) 
     { 
      //Some recoverable error happened 
      return true; 
     } 

     protected override void OnError(Context context, string errorId) 
     { 
      //Some more serious error happened 
     } 
    } 
} 

И mainactivity, как это

[assembly: Permission(Name = "@[email protected]_MESSAGE")] 
[assembly: UsesPermission(Name = "@[email protected]_MESSAGE")] 
[assembly: UsesPermission(Name = "com.google.android.c2dm.permission.RECEIVE")] 
[assembly: UsesPermission(Name = "android.permission.GET_ACCOUNTS")] 
[assembly: UsesPermission(Name = "android.permission.INTERNET")] 
[assembly: UsesPermission(Name = "android.permission.WAKE_LOCK")] 

namespace AzurePushNotification.Android 
{ 
    [Activity (Label = "myapp.Android", MainLauncher = true, Icon = "@drawable/icon")] 
    public class MainActivity : Activity 
    { 
     protected override void OnCreate (Bundle bundle) 
     { 
      base.OnCreate (bundle); 

      // Set our view from the "main" layout resource 
      SetContentView (Resource.Layout.Main); 

      // Initialize our Gcm Service Hub 
      GcmService.Initialize (this); 

      // Register for GCM 
      GcmService.Register (this); 
     } 
    } 
} 
+0

Не могли бы вы указать, где именно происходит эта ошибка? т. е. какая линия? Вы отлаживали его, чтобы узнать, где именно код разбивается? –

+0

Ошибка происходит в событии OnMessage, это действительно странно, когда я отменяю ShowLocalNotification (намерение); внутри события OnMessage, все равно такая же ошибка происходит в конце события onmessage. – slayer35

+0

Если вы отметили сообщение в событии 'OnMessage', каков его результат? Может быть, он получен в неправильном формате, который на самом деле странный? –

ответ

0

я, наконец, нашел ошибку, https://www.nuget.org/packages/Xam.Plugin.AzurePushNotification/ этот плагин вызывает ошибку .Когда я удалить это, не более error.I угадаю, что этот плагин azurepush должен использоваться один, его вроде бы переопределить некоторые методы, если вы попытаетесь вызывать push-сообщения напрямую GCM.So использовать только этот плагин. Не держите его в проекте, если вы не будете использовать этот плагин.