Hi,
I'm getting the following error when I have both file_picker and android_alarm_manager packages installed:
E/MethodChannel#file_picker( 3336): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference
E/MethodChannel#file_picker( 3336): at androidx.core.content.ContextCompat.checkSelfPermission(ContextCompat.java:544)
E/MethodChannel#file_picker( 3336): at com.mr.flutter.plugin.filepicker.FilePickerPlugin.checkPermission(FilePickerPlugin.java:127)
E/MethodChannel#file_picker( 3336): at com.mr.flutter.plugin.filepicker.FilePickerPlugin.startFileExplorer(FilePickerPlugin.java:169)
E/MethodChannel#file_picker( 3336): at com.mr.flutter.plugin.filepicker.FilePickerPlugin.onMethodCall(FilePickerPlugin.java:119)
E/MethodChannel#file_picker( 3336): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#file_picker( 3336): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188)
E/MethodChannel#file_picker( 3336): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
E/MethodChannel#file_picker( 3336): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#file_picker( 3336): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#file_picker( 3336): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#file_picker( 3336): at android.app.ActivityThread.main(ActivityThread.java:6541)
E/MethodChannel#file_picker( 3336): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#file_picker( 3336): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/MethodChannel#file_picker( 3336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I replicated this in a clean project with the following in the pubspec.yaml:
android_alarm_manager: ^0.4.1+6
file_picker: ^1.3.3
Flutter doctor:
[鈭歖 Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648], locale en-ZA)
[鈭歖 Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[鈭歖 Android Studio (version 3.3)
[鈭歖 Android Studio (version 3.0)
[鈭歖 IntelliJ IDEA Community Edition (version 2018.3)
[鈭歖 VS Code (version 1.32.3)
[鈭歖 Connected device (2 available)
Thanks!
Hi, thanks for reporting.
At a first glance the issue seems to come from ContextCompat.checkSelfPermission(activity, permission); that is called from file_picker layer but then a null pointer happens on the android x compat side. Maybe due to some conflict? Is the alarma manager on the android x as well?
I'm afraid that this can't be handled by file_picker's side.
Hi, yes android_alarm_manager is on android x. I will try and track down the issue as well.
Could I also suggest removing the permission checking, or making it optional. I know it's convenient, but this package should not take on that responsibility in my opinion.
It needs to check because it will ask for permission if you don鈥檛 have it already. That鈥檚 the only reason why.
Hi no problem, just a thought. I found the cause to be similar to what happened here: https://github.com/flutter/plugins/pull/1125. Adding the following check to registerWith fixed it:
if (registrar.activity() == null) {
return;
}
@lucien-theron is this fixed already? I saw that #156 is already closed. If so, feel free to close this as well.
@miguelpruivo that was for another plugin having the same issue. They fixed it the same way I did in the above PR I made. So if you can merge that PR then we good to go.
Right. As long as the iOS side is done as well it can be merged.
Waiting for that. If you don't have experience with iOS/Obj-C I may look into it later.
Thank you.
Okay thanks, I think its an Android specific issue but you are welcome to look into it. Reason for issue was highlighted here: https://github.com/transistorsoft/flutter_background_fetch/issues/22#issuecomment-481658481
Merged and published.
Thank you for contributing.