I am having difficulties with using the file name returned from the ContentChooser
I illustrated these in the small attached project.
In short, I look for a picture file using the ContentChooser. When selected, I display it in an ImageView.
I also save the Dir and FileName variables returned by the ContentChooser in order to be able to reopen the activity with that image preloaded.
This works fine the first time, when I choose the image and display it. If I leave the activity and return to it, I get an error (below) when I try to load the file in the ImageView:
(the line starting with "Cannot find MapFile:" is logged by the app)
The line causing the error is:
I have added the following permissions to the manifest:
Note that this works fine every time if I use the "normal" path (File.DirRootExternal & "/Downloads") and filename for the file, so it seems as if the file format used by the ContentChooser requires different permissions?
I illustrated these in the small attached project.
In short, I look for a picture file using the ContentChooser. When selected, I display it in an ImageView.
I also save the Dir and FileName variables returned by the ContentChooser in order to be able to reopen the activity with that image preloaded.
This works fine the first time, when I choose the image and display it. If I leave the activity and return to it, I get an error (below) when I try to load the file in the ImageView:
B4X:
Error occurred on line: 120 (Main)
java.lang.SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{5a536e3 26867:b4a.example/u0a120} (pid=26867, uid=10120) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3577)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1471)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1090)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:944)
at android.content.ContentResolver.openInputStream(ContentResolver.java:664)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:206)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:516)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
at b4a.example.main._loadmap(main.java:437)
at b4a.example.main._activity_resume(main.java:429)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at b4a.example.main.afterFirstLayout(main.java:108)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Cannot find MapFile: ContentDircontent://com.android.externalstorage.documents/document/primary%3ADownload%2Fmap_sample.png
** Activity (main) Pause, UserClosed = false **
The line causing the error is:
B4X:
bm.Initialize( Starter.MapDir, Starter.MapFile )
I have added the following permissions to the manifest:
B4X:
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.MANAGE_DOCUMENTS)
Note that this works fine every time if I use the "normal" path (File.DirRootExternal & "/Downloads") and filename for the file, so it seems as if the file format used by the ContentChooser requires different permissions?