Android Question Can't create directory or file

Discussion in 'Android Questions' started by MarcRB, Dec 23, 2018.

  1. MarcRB

    MarcRB Member Licensed User

    Hi I do have two tablets.

    1. Asus Zenpad Z380M 8inch
    2. Lenovo Tab4 8inch (Android 8.1.0)

    Only at the Lenovo I can't create a directory or file in /storage/emulated/0
    (= File.DirRootExternal)
    This small test fails on the Lenovo:

    Code:
    Msgbox(File.DirRootExternal,"Show location of rootext.")
      
    File.MakeDir(File.DirRootExternal, "DataHelloWorld")
    If File.Exists(File.DirRootExternal, "DataHelloWorld"Then
         
    Msgbox("Folder created. Yes!","Test")
    Else
          
    Msgbox("Folder is not created. Why?","Test"'this is the result
    End If
    I allready added the next line to the manifest.
    Code:
    AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>)
    Outside my B4A app I can create a directory in that location using a commercial filemanager app.
    With my B4A app I can succesfully check if the directory exists, but it is still not possible to write anything in that folder.

    Extra info:
    There is enough diskspace, no warning or error and no sd-card is inserted in the device.
    Also there is no cabled connetion with a computer.
    I can use File.DirDefaultExternal instead, and that works fine. The folder is created and writebale inside, but I want the data stay intact after removing or re-Installing the app. That is not possible at that location. Therefore I try to use rootexternal.

    Can anybody help me solving this?
     
  2. Filippo

    Filippo Expert Licensed User

    MarcRB and Computersmith64 like this.
  3. MarcRB

    MarcRB Member Licensed User

    It is solved now. By adding a runtime permission
    Yes is found that, but because of this line
    , I tought it was only for older tablets with this problem and it wouldn't help me. But I was wrong it was very helpfull even for Android 8.1.

    Code:
    Sub Process_Globals
          
    Private rp As RuntimePermissions
    End Sub

    Sub Activity_PermissionResult (Permission As String, Result As Boolean)
        
    If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
            
    If Result = True Then

               
    ' *** here my file writing stuf

                
    If File.Exists(modCode.gstrDataFolder, "config.ini") = False Then
                    
    StartActivity("actLicense"
                
    Else
                    initLogin 
                
    End If
            
    Else
                    
    Msgbox("No permission for writing files.","No permission for writing files")
            
    End If
        
    End If
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    If FirstTime = True Then
            rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        
    End If
    End Sub
     
    Filippo likes this.
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