ich verwende xam.plugin.pushnotification in meinem xamarin.forms ProjektFehler beim registrieren xam.plugin.pushnotification
meine Haupttätigkeit
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
//inicializa imageCircle
ImageCircleRenderer.Init();
//inicializa o mapa
global::Xamarin.FormsMaps.Init(this, bundle);
//shared Preferences
App.Init(new AndroidUserPreferences());
//Gerenciador de memória
CachedImageRenderer.Init();
try
{
AppContext = this.ApplicationContext;
CrossPushNotification.Initialize<CrossPushNotificationListener>("mysendernumbers");
StartPushService();
CrossPushNotification.Current.Register();
}
catch (Exception e)
{
var s = e.Message;
}
AndroidUserPreferences sharedPref = new AndroidUserPreferences();
//if (sharedPref.GetString("token") == " ")
//{
GetTokenTask myTask = new GetTokenTask();
myTask.Execute(this);
//}
LoadApplication(new App());
}
public static void StartPushService()
{
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
public static void StopPushService()
{
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(Context.AlarmService);
alarm.Cancel(pintent);
}
}
Mein Zuhörer in meine pcl
public class CrossPushNotificationListener : IPushNotificationListener
{
public void OnMessage(JObject values, DeviceType deviceType)
{
Debug.WriteLine("Message Arrived");
}
public void OnRegistered(string token, DeviceType deviceType)
{
Debug.WriteLine(string.Format("Push Notification - Device Registered - Token : {0}", token));
}
public void OnUnregistered(DeviceType deviceType)
{
Debug.WriteLine("Push Notification - Device Unnregistered");
}
public void OnError(string message, DeviceType deviceType)
{
Debug.WriteLine(string.Format("Push notification error - {0}",message));
}
public bool ShouldShowNotification()
{
return true;
}
}
}
Registrierung (versucht LOL) in app.cs (PCL)
public App()
{
InitializeComponent();
CrossPushNotification.Current.Register();
MainPage = new NavigationPage(new Views.Splash2());
}
Ich erhalte diese Fehlermeldung nach Versuch zu registrieren .... (in onerror Methode)
java.io.IOException: INVALID_PARAMETERS \ n bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in < 896ad1d315ca4ba7b117efb8dacaedcf>: 0 \ n unter Java.Interop.JniEnvironment + InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference-Instanz, Java.Interop.JniMethodInfo-Methode, Java.Interop.JniArgumentValue * args) [0x00069] in < 25999cc1fde6426b852c2e027711c254>: 0 \ n bei Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr-Projekt, System.IntPtr jmethod, Android.Runtime.JValue * parms) [0x0000e] in < 7a2bbe1fcaec4467930361ae212aeea9>: 0 \ n bei Android.Gms.Gcm.GcmPubSub.Subscribe (System.String registrationToken, System.String topic, Android.OS.Bundle Extras) [0x00096] in < 442f26a0595046369060be9502394e67>: 0 \ n bei PushNotification.Plugin .PushNotificationRegistrationIntentService.SubscribeTopics (System.String Token) [0x00023] in < 06cf100f14f94017b47f90010ef822f3>: 0 \ n bei PushNotification.Plugin.PushNotificationRegistrationIntentService.OnHandleIntent (Android.Content.Intent Vorsatz) [0x0004a] in < 06cf100f14f94017b47f90010ef822f3>: 0 \ n - - Ende der verwalteten Java.IO.IOException-Stapelverfolgung --- \ njava.io.IOException: INVALID_PARAMETERS \ n \ tat com.google.android.gms.iid.zzc.zzb (Unbekannte Quelle) \ n \ tat com.google .android.gms.iid.zzc.zza (Unbekannte Quelle) \ n \ tat com.google.android.gms.iid.InstanceID.zzc (Unbekannte Quelle) \ n \ tat com.google.android.gms.iid.InstanceID .getToken (unbekannte Quelle) \ n \ tat com.google.and roid.gms.gcm.GcmPubSub.subscribe (Unknown Source) \ n \ TAT md563bb5d7cd114ceda82ec85fb57ce3637.PushNotificationRegistrationIntentService.n_onHandleIntent (native Methode) \ n \ TAT md563bb5d7cd114ceda82ec85fb57ce3637.PushNotificationRegistrationIntentService.onHandleIntent (PushNotificationRegistrationIntentService.java:37) \ n \ TAT android.app. IntentService $ ServiceHandler.handleMessage (IntentService.java:65) \ n \ tat android.os.Handler.dispatchMessage (Handler.java:102) \ n \ tat android.os.Looper.loop (Looper.java:146) \ n \ tat android.os.HandlerThread.run (HandlerThread.java:61) \ n - Registrieren - PushNotificationRegistationIntentService