Closed vandelpal closed 9 years ago
Please provide ADB log or Stack Trace
E/AndroidRuntime(14567): FATAL EXCEPTION: main E/AndroidRuntime(14567): java.lang.Error: FATAL EXCEPTION [main] E/AndroidRuntime(14567): Unity version : 5.0.1f1 E/AndroidRuntime(14567): Device model : samsung GT-P5110 E/AndroidRuntime(14567): Device fingerprint: samsung/espresso10wifixx/espresso10 wifi:4.2.2/JDQ39/P5110XXDMI1:user/release-keys E/AndroidRuntime(14567): E/AndroidRuntime(14567): Caused by: java.lang.RuntimeException: Unable to start receiver net.agasper.unitynotification.UnityNotificationManager: java.lang.NullP ointerException: name == null E/AndroidRuntime(14567): at android.app.ActivityThread.handleReceiver(Act ivityThread.java:2448) E/AndroidRuntime(14567): at android.app.ActivityThread.access$1600(Activi tyThread.java:150) E/AndroidRuntime(14567): at android.app.ActivityThread$H.handleMessage(Ac tivityThread.java:1356) E/AndroidRuntime(14567): at android.os.Handler.dispatchMessage(Handler.ja va:99) E/AndroidRuntime(14567): at android.os.Looper.loop(Looper.java:175) E/AndroidRuntime(14567): at android.app.ActivityThread.main(ActivityThrea d.java:5279) E/AndroidRuntime(14567): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(14567): at java.lang.reflect.Method.invoke(Method.java:5 11) E/AndroidRuntime(14567): at com.android.internal.os.ZygoteInit$MethodAndA rgsCaller.run(ZygoteInit.java:1102) E/AndroidRuntime(14567): at com.android.internal.os.ZygoteInit.main(Zygot eInit.java:869) E/AndroidRuntime(14567): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(14567): Caused by: java.lang.NullPointerException: name == null
E/AndroidRuntime(14567): at java.lang.Class.classForName(Native Method) E/AndroidRuntime(14567): at java.lang.Class.forName(Class.java:217) E/AndroidRuntime(14567): at java.lang.Class.forName(Class.java:172) E/AndroidRuntime(14567): at net.agasper.unitynotification.UnityNotificati onManager.onReceive(UnityNotificationManager.java:88) E/AndroidRuntime(14567): at android.app.ActivityThread.handleReceiver(Act ivityThread.java:2441) E/AndroidRuntime(14567): ... 10 more
Hello,
First of all, thanks for the great job, the plugin works like a charm.
I can confirm the crash. Anything new about this issue ?
David
Hello everyone, plugin was not tested on Unity 5+
Works well under Unity 5. Could it be the call of CancelNotification before SendNotification ?
David
Hi I just encounter the same issue, anyway to make it work ? I have to cancel the scheduled notification
when game start and schedule a notifcation when quit game
I'm also having the same issue. Any work around ? im on unity 5.4.
You can find solution here: https://github.com/Agasper/unity-android-notifications/issues/17
"If you store all unique notifications identifiers, and cancel only scheduled notification then cancelAllNotifications method is easy to write and this fatal exception will not occur!"
Will this work ? public static void CancelAll(){ NotificationManager notificationManager = (NotificationManager)UnityPlayer.currentActivity.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); }
I have two functions in my version of plugin:
public static void CancelNotification(int id) { Activity currentActivity = UnityPlayer.currentActivity; AlarmManager am = (AlarmManager)currentActivity.getSystemService("alarm"); Intent intent = new Intent(currentActivity, UnityNotificationManager.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(currentActivity, id, intent, 0); am.cancel(pendingIntent); }
public static void ClearAllNotifications() { Context context = UnityPlayer.currentActivity.getBaseContext(); NotificationManager nm = (NotificationManager)context.getSystemService("notification"); nm.cancelAll(); }
Fist function stop scheduled notification with id. You can not call it for not scheduled notifications!! So we have to remember all setted notifications and time and then check that the notification is still scheduled and not fire. Second function (as well as in your code) оnly clears the notification shown in the status bar. Android does not have a method for the removal of all scheduled notifications!
Has Anyone updated that code ?
i commented the Cancel Notification Code and it worked fine but i want to cancel all scheduled notifications once the app is launched , how to do that?
Steps for reproduce:
If you no call CancelNotification, everything is good. Exception in line: unityClassActivity = Class.forName(unityClass); (Nullpointer)