thanks it works OK
EDIT: file saved ok, folder and file are visible now, but failed to open file with associated application
i changed code to this:
Public Sub Initialize
Dim p As Phone
If p.SdkVersion >= 24 Or File.ExternalWritable = False Then
UseFileProvider = True
'SharedFolder = File.Combine(File.DirInternal, "shared")
Dim rp As RuntimePermissions
SharedFolder = rp.GetSafeDirDefaultExternal("shared")
File.MakeDir("", SharedFolder)
Else
UseFileProvider = False
SharedFolder = rp.GetSafeDirDefaultExternal("shared")
End If
Log($"Using FileProvider? ${UseFileProvider}"$)
End Sub
but this code failed to run, and I get error exception
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
Starter.Provider.SetFileUriAsIntentData(in, Filename)
in.SetType("text/csv")
StartActivity(in)
here is code on line 40:
'Replaces the intent Data field with the file uri.
'Resets the type field. Make sure to call Intent.SetType after calling this method
Public Sub SetFileUriAsIntentData (Intent As Intent, FileName As String)
Dim jo As JavaObject = Intent
jo.RunMethod("setData", Array(GetFileUri(FileName)))
Intent.Flags = Bit.Or(Intent.Flags, 1) 'FLAG_GRANT_READ_URI_PERMISSION
End Sub
Error occurred on line: 40 (FileProvider)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at com.etripClient.fileprovider._getfileuri(fileprovider.java:155)
at com.etripClient.fileprovider._setfileuriasintentdata(fileprovider.java:106)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1760)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7438)
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:989)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.etripClient/files/shared/tt.CSV
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
... 23 more
(Exception) java.lang.Exception: java.lang.reflect.InvocationTargetException
** Activity (triprequests) Pause, UserClosed = false **