This concerns writing to my phone's External Storage Download folder using B4XPages . I've seen old threads at https://www.b4x.com/android/forum/t...ns-android-6-0-permissions.67689/page-3#posts and https://www.b4x.com/android/forum/t...folder-with-getsafedirdefaultexternal.110020/ So I'm starting a new thread as requested in those threads.
I want to copy a file from Internal Storage (where a .jpg file was downloaded successfully from a https URL in the app where the coding below originates from) to the Download folder in External Storage: the purpose of this is so that I can view the file in my the phone's Photos or similar Android app.
The https download works Ok as the log shows both "File was downloaded successfully" and "File was copied successfully to Internal Storage".
However, there is a runtime error of "java.io.FileNotFoundException: /storage/emulated/0/download/Summer.jp (Permission Denied)" on the File.Copy line. What should I change in the above code?
BTW The previously referred to threads recommend using RuntimePermissions with GetSafeDirDefaultExternal: I've tried code of RuntimePermissions, after including the RuntimePermissions library, but that gives a Compiler error on RuntimePermissions. Why? Also, one of those threads states that the user will be asked to give a permission at runtime and I don't want that to happen. So should I not use RuntimePermissions with GetSafeDirDefaultExternal?
I want to copy a file from Internal Storage (where a .jpg file was downloaded successfully from a https URL in the app where the coding below originates from) to the Download folder in External Storage: the purpose of this is so that I can view the file in my the phone's Photos or similar Android app.
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private WebServer As String = "https://rose.myddns.me"
Private ISFolder As String = xui.DefaultFolder
Private FileName As String = "Summer.jpg"
Private ASFolder As String File.DirRootExternal & "/Download"
Sub Download
Dim HTTP1 As HttpJob
Dim ServerPath As String = WebServer & "/" & FileName
HTTP1.Initialize("", Me)
HTTP1.Download(ServerPath)
Wait For (HTTP1) JobDone(HTTP1 As HttpJob)
If HTTP1.Success Then
Log("File was downloaded successfully")
Dim out As OutputStream = File.OpenOutput(ISFolder, FileName, False)
File.Copy2(HTTP1.GetInputStream, out)
out.Close '<------ very important
Log("File was copied successfully to Internal Storage")
Else
Log(HTTP1.GetString)
Log("Error downloading file")
End If
HTTP1.Release
Sleep(0)
File.Copy(ISFolder, FileName, ASFolder, FileName)
The https download works Ok as the log shows both "File was downloaded successfully" and "File was copied successfully to Internal Storage".
However, there is a runtime error of "java.io.FileNotFoundException: /storage/emulated/0/download/Summer.jp (Permission Denied)" on the File.Copy line. What should I change in the above code?
BTW The previously referred to threads recommend using RuntimePermissions with GetSafeDirDefaultExternal: I've tried code of RuntimePermissions, after including the RuntimePermissions library, but that gives a Compiler error on RuntimePermissions. Why? Also, one of those threads states that the user will be asked to give a permission at runtime and I don't want that to happen. So should I not use RuntimePermissions with GetSafeDirDefaultExternal?