hedzr / android-file-chooser

a lightweight file/folder chooser or picker
Apache License 2.0
284 stars 62 forks source link

Runtime Exception on Android 6 devices #60

Open ytheekshana opened 5 years ago

ytheekshana commented 5 years ago

Got a runtime exception only on Android 6 devices after 1.1.17 update

Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=347, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.ytheekshana.deviceinfo/com.obsez.android.lib.filechooser.permissions.PermissionActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content at android.app.ActivityThread.deliverResults(ActivityThread.java:5004) at android.app.ActivityThread.handleSendResult(ActivityThread.java:5047) at android.app.ActivityThread.access$1600(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Caused by android.util.AndroidRuntimeException: requestFeature() must be called before adding content at com.android.internal.policy.PhoneWindow.requestFeature(PhoneWindow.java:411) at com.android.internal.app.AlertController.installContent(AlertController.java:250) at android.app.AlertDialog.onCreate(AlertDialog.java:437) at android.app.Dialog.dispatchOnCreate(Dialog.java:733) at android.app.Dialog.show(Dialog.java:469) at com.obsez.android.lib.filechooser.ChooserDialog.showDialog(ChooserDialog.java:568) at com.obsez.android.lib.filechooser.ChooserDialog.access$000(ChooserDialog.java:65) at com.obsez.android.lib.filechooser.ChooserDialog$1.onPermissionGranted(ChooserDialog.java:604) at com.obsez.android.lib.filechooser.permissions.PermissionActivity.onRequestPermissionsResult(PermissionActivity.java:81) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7291) at android.app.Activity.dispatchActivityResult(Activity.java:7169) at android.app.ActivityThread.deliverResults(ActivityThread.java:5000) at android.app.ActivityThread.handleSendResult(ActivityThread.java:5047) at android.app.ActivityThread.access$1600(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

hedzr commented 5 years ago

hmmm, it's a bug. fortunately, or unfortunately, it occurs just under android M: https://issuetracker.google.com/issues/37061719

they announced one or two workaround(s). it's not fit for me. but i tried to avoid it at the next commit. see my commit later. And, there is another way to disable the exception: DON'T enable displayPath in your case. That means: call .displayPath(false).

hedzr commented 5 years ago

if you like displayPath, retrieve the patch (8d6156f6d2, or 5257025c2d) by following jitpack doc:

https://jitpack.io/#hedzr/android-file-chooser/8d6156f6d2

ytheekshana commented 5 years ago

Ok. I'll call .displayPath(false) as I don't need the path displayed. Thanks

Guiorgy commented 5 years ago

hmm, I've been testing it on a Kitkat emulator, yet I am failing to replicate this exception

ytheekshana commented 5 years ago

hmm, I've been testing it on a Kitkat emulator, yet I am failing to replicate this exception

Happened to me only on Android 6

Guiorgy commented 5 years ago

fortunately, or unfortunately, it occurs just under android M

thought any api < 26? I'll check M then

edit: indeed, I got the error...

hedzr commented 5 years ago

the patch is a work around for M, and the operating expirences has not been break. i guess that's ok now.

Guiorgy commented 5 years ago

there is a simpler way to make it work though:

if (_alertDialog != null && _alertDialog.isShowing() && _displayPath) { ...

just need to check that _alertDialog is already showing.

Guiorgy commented 5 years ago

1.1.19 out, please confirm that the problem has been solved.

omarman2 commented 5 years ago

omarman_2006a@hotmail.com

kartik1225 commented 5 years ago

Is that issue is resolved? If yes then how?