Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with permission checker and android_alarm_manager #65

Closed
lucien-theron opened this issue Apr 2, 2019 · 10 comments
Closed

Error with permission checker and android_alarm_manager #65

lucien-theron opened this issue Apr 2, 2019 · 10 comments
Labels
bug Something isn't working on hold triage Further information is requested

Comments

@lucien-theron
Copy link

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!

@miguelpruivo
Copy link
Owner

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.

@miguelpruivo miguelpruivo added bug Something isn't working triage Further information is requested on hold labels Apr 2, 2019
@lucien-theron
Copy link
Author

Hi, yes android_alarm_manager is on android x. I will try and track down the issue as well.

@lucien-theron
Copy link
Author

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.

@miguelpruivo
Copy link
Owner

It needs to check because it will ask for permission if you don’t have it already. That’s the only reason why.

@lucien-theron
Copy link
Author

lucien-theron commented Apr 2, 2019

Hi no problem, just a thought. I found the cause to be similar to what happened here: flutter/plugins#1125. Adding the following check to registerWith fixed it:
if (registrar.activity() == null) { return; }

@miguelpruivo
Copy link
Owner

@lucien-theron is this fixed already? I saw that #156 is already closed. If so, feel free to close this as well.

@lucien-theron
Copy link
Author

lucien-theron commented Apr 17, 2019

@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.

@miguelpruivo
Copy link
Owner

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.

@lucien-theron
Copy link
Author

Okay thanks, I think its an Android specific issue but you are welcome to look into it. Reason for issue was highlighted here: transistorsoft/flutter_background_fetch#22 (comment)

@miguelpruivo
Copy link
Owner

Merged and published.

Thank you for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on hold triage Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants