Android Question Copy from download folder in OREO

Discussion in 'Android Questions' started by GEoffT, Jul 11, 2018.

  1. GEoffT

    GEoffT Member Licensed 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:

    Code:
    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 StringAs 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
     
  2. Mahares

    Mahares Well Known Member Licensed User

    You need runtime permissions:
    Code:
    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 StringAs 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
     
    Erel likes this.
  3. DonManfred

    DonManfred Expert Licensed User

    Erel likes this.
  4. GEoffT

    GEoffT Member Licensed User

    Thank you DonManfred and Mahares.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice