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

Permission callbacks called even when not requested #19

Closed
ened opened this issue Dec 21, 2018 · 7 comments
Closed

Permission callbacks called even when not requested #19

ened opened this issue Dec 21, 2018 · 7 comments
Labels
bug Something isn't working

Comments

@ened
Copy link
Contributor

ened commented Dec 21, 2018

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.

@rrarey02
Copy link

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

@miguelpruivo miguelpruivo pinned this issue Dec 26, 2018
@miguelpruivo miguelpruivo added the bug Something isn't working label Dec 26, 2018
@miguelpruivo
Copy link
Owner

miguelpruivo commented Dec 26, 2018

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.

@ened
Copy link
Contributor Author

ened commented Dec 26, 2018

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

@miguelpruivo
Copy link
Owner

miguelpruivo commented Dec 26, 2018

I’m glad it solved. Still, I’m 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’t relate it to the stacktrace you’ve posted here.

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

@rrarey02
Copy link

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

@kgamecarter
Copy link

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

@miguelpruivo
Copy link
Owner

Closing issue. Version 1.1.0 released. See changelog

@miguelpruivo miguelpruivo unpinned this issue Dec 27, 2018
@Zfinix Zfinix mentioned this issue Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants