Android Question Copy from download folder in OREO

GEoffT

Member
Licensed User
Longtime User
My app has need to copy a file from the downloads folder.

This works fine except with Oreo. Is this a fuction of this android version or a function of my Oreo device (Huawei P20)?

I am using <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/>

The move code that I am using is as follows:

B4X:
FileMove(File.Combine(File.DirRootExternal, "Download"), "TTBcopy.dback",File.DirDefaultExternal, "TTB.db")
.
.
.
Sub FileMove(SourceFolder As String, SourceFile As String, TargetFolder As String, TargetFile As String) As Boolean
    Dim source, target As JavaObject
    Log(SourceFolder &" " & SourceFile &" to " & TargetFolder & " " & TargetFile)
    source.InitializeNewInstance("java.io.File", Array(SourceFolder, SourceFile))
    target.InitializeNewInstance("java.io.File", Array(TargetFolder, TargetFile))
    Return source.RunMethod("renameTo", Array(target))
End Sub
 

Mahares

Expert
Licensed User
Longtime User
This works fine except with Oreo. Is this a fuction of this android version o
You need runtime permissions:
B4X:
Sub Globals
    Private rp As RuntimePermissions 'need runtimepermissions lib
End Sub

Sub Activity_Create(FirstTime As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        MsgboxAsync("No permission to access external storage", "")
        Return
    End If
    FileMove(File.Combine(File.DirRootExternal, "Download"), "TTBcopy.dback",rp.GetSafeDirDefaultExternal(""), "TTB.db")
End Sub

Sub FileMove(SourceFolder As String, SourceFile As String, TargetFolder As String, TargetFile As String) As Boolean
    Dim source, target As JavaObject
    Log(SourceFolder &" " & SourceFile &" to " & TargetFolder & " " & TargetFile)
    source.InitializeNewInstance("java.io.File", Array(SourceFolder, SourceFile))
    target.InitializeNewInstance("java.io.File", Array(TargetFolder, TargetFile))
    Return source.RunMethod("renameTo", Array(target))
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top