Flutter_file_picker: Permission callbacks called even when not requested

Created on 21 Dec 2018  路  7Comments  路  Source: miguelpruivo/flutter_file_picker

My App needs a few permissions to work, like Location or "ReadExternalStorage".
I will use the simple_permissions plugin to gather the location permission.
However, once that permission is granted, the file_picker callback at https://github.com/miguelpruivo/plugins_flutter_file_picker/blob/e496cfc060d724b1da46f295e4085cb9748448d3/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerPlugin.java#L99 will be called as well. This causes a crash:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.
pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.company.app/com.company.app.MainActivity}: android.content.Activ
ityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] }
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4361)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4403)
    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6680)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.catego
ry.OPENABLE] }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2007)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
    at android.app.Activity.startActivityForResult(Activity.java:4586)
    at android.app.Activity.startActivityForResult(Activity.java:4544)
    at com.mr.flutter.plugin.filepicker.FilePickerPlugin.startFileExplorer(FilePickerPlugin.java:163)
    at com.mr.flutter.plugin.filepicker.FilePickerPlugin.access$300(FilePickerPlugin.java:26)
    at com.mr.flutter.plugin.filepicker.FilePickerPlugin$2.onRequestPermissionsResult(FilePickerPlugin.java:99)
    at io.flutter.app.FlutterPluginRegistry.onRequestPermissionsResult(FlutterPluginRegistry.java:191)
    at io.flutter.app.FlutterActivityDelegate.onRequestPermissionsResult(FlutterActivityDelegate.java:125)
    at io.flutter.app.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:133)
    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7616)
    at android.app.Activity.dispatchActivityResult(Activity.java:7466)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4354)
    ... 11 more

From my point of view, the plugin should not rely on a static request code of zero (which may be used by other plugins, indeed) but perhaps a .hashCode() number based on the plugin name.

bug

All 7 comments

I'm running into this issue as well in the same scenario and as a result am unable to use the plugin.

From the exception itself it seems that your system can't find any app that can handle the file picking which is expected, since it's launching the intent to look for a supported app that can supports both the action and category. It's odd anyway, but some ROM's might do this. Does that happen on the emulator?

@rrarey02 @ened would you mind to add the plugin to your project using beta which is ahead of master and let me know if still happens?

dependencies:
  file_picker:
    git:
      url: git://github.com/miguelpruivo/plugins_flutter_file_picker.git
      ref: beta

If so, some logs would be appreciated so I can fix it ASAP. I can't seem to replicate the issue which makes the task harder.

Any PR will also be welcome if you manage to fix it yourself.

@miguelpruivo thank you for the quick fix. I can confirm the issue is resolved in beta. Test was done on an actual device as before.

I鈥檓 glad it solved. Still, I鈥檓 not quite sure about what was causing the issue @ened. It was a blind hit and only changed the request code to use the class hashCode instead of static 0 as you suggested. But I can鈥檛 relate it to the stacktrace you鈥檝e posted here.

@rrarey02 let me know if it鈥檚 also working for you before I close the issue. Thank you.

@miguelpruivo, I just applied the fix and it is working great in Android Studio's emulator. Haven't tried in a device yet but I'll take @ened's word for it. Thank you so much!

has same issue at 1.0.3.
And git beta work for me

Closing issue. Version 1.1.0 released. See changelog

Was this page helpful?
0 / 5 - 0 ratings