收到推送通知并关闭应用程序时应用程序崩溃

时间:2018-06-07 15:37:25

标签: android xamarin xamarin.forms crash android-notifications

收到推送通知后,我的Xamarin Android应用程序崩溃了。!

这是错误:

  

System.NotSupportedException:无法激活Java类型的JNI句柄0xbee2dcd8(key_handle 0x1302a92b)' md53ff9574f15073ce2830b1527af878807 / GcmListener'作为托管类型' DriversInfo.Droid.GcmListener'。 ---> System.ArgumentNullException:值不能为null。

以下是接收通知的代码(GCMListener):

public override void OnMessageReceived(string from, Bundle data)
    {
        System.Diagnostics.Debug.WriteLine($"notification data : {data}");

        //Log.Debug("MyGcmListenerService", "OnMessageReceived");
        var message = data.GetString("message");
        System.Diagnostics.Debug.WriteLine("MyGcmListenerService - From:    " + from);
        System.Diagnostics.Debug.WriteLine("MyGcmListenerService - Message: " + message);

        var isSilent = data.GetBoolean("isSilent");

        System.Threading.Tasks.Task.Run(async () => await this.Engine.ResumeAsync());

        if (!isSilent)
        {
            NotificationHelper.DisplayNotification(this, "Drivers Info", message);
        }
    }

显示通知的代码:

        public static bool DisplayNotification(Context context, string title, string desc,
                                           NotificationId notificationId = 0)
    {
        // Set up an intent so that tapping the notifications returns to this app:
        Intent intent = new Intent(context, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

        // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
        const int pendingIntentId = 0;
        PendingIntent pendingIntent =
            PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.UpdateCurrent);

        var builder = new NotificationCompat.Builder(context)
            .SetAutoCancel(true)
            .SetContentTitle(title)
            .SetContentText(desc)
            .SetContentIntent(pendingIntent)
            .SetSmallIcon(Resource.Drawable.Logo);

        //if (Settings.AppAcceptsSoundNotifications)
        builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

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

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

        notificationManager?.Notify((int) notificationId, notification);
        return true;
    }

我没有写这段代码,我想了解更多相关内容! 我有点失望和新的Xamarin / Android开发者,需要社区帮助/解释。

谢谢;)

修改

以下是有关应用崩溃的详细信息(无上下文):

  

AndroidRuntime参数名称:Autofac.ResolutionExtensions.ResolveService(Autofac.IComponentContext上下文,Autofac.Core.Service服务,System.Collections.Generic.IEnumerable 1[T] parameters) [0x00003] in <ca1ca41f44e0487e9a15b2f64e38c7de>:0 at Autofac.ResolutionExtensions.Resolve (Autofac.IComponentContext context, System.Type serviceType, System.Collections.Generic.IEnumerable 1 [T]参数)[0x00007]中的上下文: 0 at Autofac.ResolutionExtensions.Resolve [TService](Autofac.IComponentContext context,System.Collections.Generic.IEnumerable`1 [T] parameters)[0x00000] in:0 at Autofac.ResolutionExtensions.Resolve [TService](Autofac.IComponentContext context )[0x00000] in:0中的DriversInfo.Droid.GcmListener..ctor()[0x0000c] in&lt; 41c8506acadd4ded8f0bf3c09ac45dbb&gt;:0 at(wrapper dynamic-method)System.Object.6e5c2775-7f90-4dd7-a6af-e9481e583260(intptr ,object [])at Java.Interop.TypeManager.n_Activate(System.IntPtr jnienv,System.IntPtr jclass,System.IntPtr typename_ptr,System.IntPtr signature_ptr,System.IntPtr jobject,System.IntPtr parameters_ptr)[0x000df] in&lt; 52508bfa6a8a441688f64accb5488049&gt;:0 ---内部异常堆栈跟踪结束---在Java.Interop.TypeMa nager.n_Activate(System.IntPtr JNIEnv的,System.IntPtr JCLASS,System.IntPtr typename_ptr,System.IntPtr signature_ptr,System.IntPtr jobject,System.IntPtr parameters_ptr)[0x00168]在&LT; 52508bfa6a8a441688f64accb5488049&GT;:0在(包装纸动态方法System.Object.ae816e3f-b83f-4390-af32-80f1fa8830a2(intptr,intptr,intptr,intptr,intptr,intptr)在mono.android.TypeManager.n_tivate(Native Method)的mono.android.TypeManager.Activate(TypeManager。 java:7)位于android.app的java.lang.Class.newInstance(Class.java:1690)的java.lang.reflect.Constructor.newInstance(Native Method)中的md5c4b050970b34fabb7ecdb34ca8ce9387.GcmListener。(GcmListener.java:23)。 Activity.Thread.handleCreateService(ActivityThread.java:3657)位于android.app.Handler的android.app.ActivityThread.access $ 2000(ActivityThread.java:219)android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1818)。 dispatchMessage(Handler.java:102)位于android.app.ActivityThread.main(ActivityT)的android.os.Looper.loop(Looper.java:145) hread.java:6939)at java.lang.reflect.Method.invoke(Native Method)at java.lang.reflect.Method.invoke(Method.java:372)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller。在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)上运行(ZygoteInit.java:1404)

0 个答案:

没有答案