Android Question How to solve Permission denied in Android 4.4 Kitkat

Discussion in 'Android Questions' started by Rick Harris, May 18, 2015.

  1. Rick Harris

    Rick Harris Well-Known Member Licensed User

    Google apparently has (to the anger of many people) blocked the ability to read and write to the external SD card from Android 4.4 upwards. The strange thing is that a "permission denied" error also occurs when using the Random Access File (RAF) library simply when reading a file! How can this be resolved?

    I have added the following lines to the manifest:

    AddPermission
    (android.permission.READ_EXTERNAL_STORAGE)

    AddPermission
    (android.permission.WRITE_EXTERNAL_STORAGE)
    but it has no effect.

    Furthermore, the File.DirRootExternal command does not work with my brand new Samsung Galaxy Tab S 8.4. It should report: /storage/extSdCard/ but doesn't!


    Any suggestions would be welcome. I don't want to root my device, which seems to be the only way to get access to the externa SD card. I thought Google's slogan was: "Don't do evil"....
     
  2. NJDude

    NJDude Expert Licensed User

    You are confusing the INTERNAL SDCard with the EXTERNAL SDCard, Google has changed the permissions to the latter.
     
    Peter Simpson likes this.
  3. Rick Harris

    Rick Harris Well-Known Member Licensed User

    I wouldn't call internal memory an "SD card", but what's in a name. It is really horrible what Google has done.
    In the mean time I have solved the RAF file problem. The "permission denied" error does not occur if the RAF is initialized with the read-only parameter set to TRUE.

    If you know how to access the external SD card with something similar to File.DirRootExternal (which does not work) then please let me know. At present I have to specify the true Samsung external SD directory name:

    "/storage/extSdCard/".
     
  4. NJDude

    NJDude Expert Licensed User

    There's no standard regarding the external storage so "/storage/extSdCard/" will only work on that Samsung (or devices that by chance use the same path).
     
    Last edited: May 19, 2015
  5. Erel

    Erel Administrator Staff Member Licensed User

    Rick Harris and NJDude like this.
  6. Rick Harris

    Rick Harris Well-Known Member Licensed User

    It seems it is now necessary to detect whether the device has Android 4.4 or higher because
    GetContext.RunMethod("getExternalFilesDirs", Array(Null)) generates an error on older devices.
    I now use something like this:
    Code:
    Dim Phone1 as Phone
    If Phone1.SdkVersion >=19 Then
       
    Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs"Array(Null))
       
    For Each p As Object In paths
          
    Log(p)
          
    'Analyse and use one of these paths
        Next
     
    Else
        
    'Use File.DirRootExternal
     End If
    If there is a better way, then please let me know!
     
    ClaudeJerome 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