flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

Issue on android 13 with android

Open georgesamirmansour opened this issue 8 months ago • 10 comments

java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/AndroidRuntime(22930): at android.app.ActivityThread.handleReceiver(ActivityThread.java:4903) E/AndroidRuntime(22930): at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0) E/AndroidRuntime(22930): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2420) E/AndroidRuntime(22930): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(22930): at android.os.Looper.loopOnce(Looper.java:226) E/AndroidRuntime(22930): at android.os.Looper.loop(Looper.java:313) E/AndroidRuntime(22930): at android.app.ActivityThread.main(ActivityThread.java:8762) E/AndroidRuntime(22930): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(22930): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) E/AndroidRuntime(22930): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) E/AndroidRuntime(22930): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/AndroidRuntime(22930): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:462) E/AndroidRuntime(22930): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:363) E/AndroidRuntime(22930): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1236) E/AndroidRuntime(22930): at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java:61) E/AndroidRuntime(22930): at android.app.ActivityThread.handleReceiver(ActivityThread.java:4894) E/AndroidRuntime(22930): ... 9 more D/CompatibilityChangeReporter(22930): Compat change id reported: 194532703; UID 10872; state: ENABLED I/Process (22930): Sending signal. PID: 22930 SIG: 9

georgesamirmansour avatar Oct 29 '23 08:10 georgesamirmansour

I got this issue after migrating from version 8 to version 16

Mighty683 avatar Nov 27 '23 23:11 Mighty683

Seems like default icon from AndroidInitializationSettings is not working anymore: var initializationSettingsAndroid = AndroidInitializationSettings('drawable/ic_action_play_arrow'); var initializationSettingsIOS = DarwinInitializationSettings(); var initializationSettings = InitializationSettings( android: initializationSettingsAndroid, iOS: initializationSettingsIOS ); await _flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveBackgroundNotificationResponse: (response) { onSelectCallback(); }, onDidReceiveNotificationResponse: (response) { onSelectCallback(); });

Had to add icon: 'drawable/ic_action_play_arrow' to my notification details: AndroidNotificationDetails( config.type, config.type, channelDescription: 'Channel for: ${config.type}', playSound: true, importance: Importance.max, priority: Priority.max, icon: 'drawable/ic_action_play_arrow')

Mighty683 avatar Nov 27 '23 23:11 Mighty683

The exception gets thrown when the specified icon for the notification does not exist. As @Mighty683 mentioned, the solution is to add the icon name to the AndroidNotificationDetails. If you do not explicitly specify an icon, the default one has to exist in your res folder which would be ic_launcher in most cases.

fleeser avatar Nov 30 '23 03:11 fleeser

I have used in both places the same icon.

AndroidInitializationSettings('drawable/ic_action_play_arrow')

So it looks like it ignored AndroidInitializationSettings

Mighty683 avatar Nov 30 '23 07:11 Mighty683

@georgesamirmansour this isn't an Android 13 issue and would indicate your icon can't be located. This is indicative of the icon not being specified properly

@Mighty683 I don't know why it's not working in your scenario but from running the example app, I can see it can show the notification with an icon when using AndroidInitializationSettings. Have you tried reproducing this with the example app? Sounds silly but have you also tried specifying it without the drawable/ path? Mentioning it as it's not needed. Another thing is have you tried this on an emulator? The emulator would have the stock Android OS so wondering if you have a device-specific issue.

On a related note, have been contemplating removing the ability to specify it this way it seems like issue reports would seem to indicate it stops working at some point. Have a suspicion that non-stock Android devices are allowing shared preferences information to be deleted and this is where the information about the default icon is being kept

MaikuB avatar Nov 30 '23 09:11 MaikuB

@georgesamirmansour this isn't an Android 13 issue and would indicate your icon can't be located. This is indicative of the icon not being specified properly

@Mighty683 I don't know why it's not working in your scenario but from running the example app, I can see it can show the notification with an icon when using AndroidInitializationSettings. Have you tried reproducing this with the example app? Sounds silly but have you also tried specifying it without the drawable/ path? Mentioning it as it's not needed. Another thing is have you tried this on an emulator? The emulator would have the stock Android OS so wondering if you have a device-specific issue.

On a related note, have been contemplating removing the ability to specify it this way it seems like issue reports would seem to indicate it stops working at some point. Have a suspicion that non-stock Android devices are allowing shared preferences information to be deleted and this is where the information about the default icon is being kept

I have tested it on emulator with android 12 and 14 and it worked.

So issue is only happening only my physical device Samsung with Android 14.

Mighty683 avatar Nov 30 '23 11:11 Mighty683

@Mighty683 a couple of questions

  1. Is this with your own app that you tested on the Android emulator and Samsung to see the differences in behaviour?
  2. Are you doing this with a clean install for each test?

If you are indeed running into a device specific issues then not something I help further with. If that is the case, it also sounds quite odd that. Haven't heard of an Android device preventing writing to shared permissions unless Samsung had decided to gate it behind a non-standard permission

Edit: originally said position when I meant position so corrected it

MaikuB avatar Nov 30 '23 12:11 MaikuB

@Mighty683 a couple of questions

1. Is this with your own app that you tested on the Android emulator and Samsung to see the differences in behaviour?

2. Are you doing this with a clean install for each test?

If you are indeed running into a device specific issues then not something I help further with. If that is the case, it also sounds quite odd that. Haven't heard of an Android device preventing writing to shared permissions unless Samsung had decided to gate it behind a non-standard position

  1. Yes
  2. Now I have retested issue on physical device with clean install and it don't happen again. Maybe migration and reinstalling application which previously had 8 version of plugin was a cause? I don't remember if I did clean install or not then.

Mighty683 avatar Nov 30 '23 13:11 Mighty683

@Mighty683 hard for me to say, if it was to do with using an older version of a plugin then I would think it had been from versions prior to 0.6.0 and that's a very old version. I mention that version in particular as the plugin use to reference resources by ID and that caused a problem as updates to an app could result in a resource getting a different ID.

Given the number of similar issues, I've seen I may have to consider deprecating the ability to specify the default icon as it sounds like some problems are to do with using shared preferences and perhaps some Android OEMs are deleting clearing shared preferences

MaikuB avatar Jan 19 '24 11:01 MaikuB

We can reproduce this issue by doing the following:

  1. Create a version of your App and register a notification
  2. Close the App and install an update for it.
  3. Don't open the app. Once the notification should be displayed, you can see the Error of the Issue in the Android Logcat.

P.S: We tested with an Obfuscated App which is configured like the example with Proguard Rules.

I hope this helps to resolve this issue

jxstxn1 avatar Mar 04 '24 14:03 jxstxn1