Android Question File.DirRootExternal not the path of the sd-card?

Discussion in 'Android Questions' started by Alexander Stolte, Jan 19, 2017.

  1. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Hello,

    In the theory you get with DirRootExternal the path of an external storage media or sd-card. Is that right?

    Because with me comes a completely different path out and try to save something under the path it saves it always on the device not on the SD.

    I add this permission to the manifest editor:
    Code:
    AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
    And writeable is true.

    Or is there another way to save the sd card? All tutorials I have read have been based on "DirRootExternal"
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    No. It returns the path to the secondary storage. On 99% of the devices this will not be an sd card.

    You can use RuntimePermissions.GetAllSafeDirsExternal to get the path of the only folder that is accessible for your app on the sd card.

    There are many discussions related to sd cards: http://www.b4x.com/search?query=sd+card
     
  3. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    I have one more question,

    I use: GetAllSafeDirExternal, as a result I get 2 paths. The second path is the sd-card. The Problem is, i cant convert an array to string. And if i use this array, i get errors.

    My Code:
    Code:
    Dim rp As RuntimePermissions
            
    Dim folders As List = rp.GetAllSafeDirsExternal("")
            
    Dim List2 As List
            List2.Initialize
            List2.AddAll(folders)
            List2.RemoveAt(
    0)

            astream.StreamFolder = List2
    Result:
    Code:
    (ArrayList) [/storage/0123-4567/Android/data/b4a.testing/files]
    Errors:

    Code:
    Error: (ErrnoException) android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    Permission to write on there is set:
    Code:
    AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
     
  4. DonManfred

    DonManfred Expert Licensed User

    Code:
    Log(rp.GetSafeDirDefaultExternal(""))
    this log the only folder on the sdcard which is writeable for your app. Usually it is the second storage (internal!).

    You dont have access to a third storage (External SDCard) starting from android 5 (or was it 4.4?). I may be wrong
     
    Last edited: Jan 21, 2017
  5. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    I use Android 6.0.1

    So is it no longer possible to write to the sd card?
     
  6. DonManfred

    DonManfred Expert Licensed User

    Correct

    Edit: if you have setup your device to use the external storage for app-installations then you may get a path on the external sdcard, But again; only THIS one Folder is writeable for your app.
    You dont have WRITE-Access to any other folder.

    You can for sure READ the files on external sdcard using my STORAGE lib. See https://www.b4x.com/android/forum/threads/donmanfreds-overview.54618/ for a list of my libs... It´s the first i published

    See Example attached
     

    Attached Files:

    Last edited: Jan 21, 2017
  7. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    This is mhhh but then the users have to deal with it. Thank you anyway.
     
  8. DonManfred

    DonManfred Expert Licensed User

    Yes, it is a restriction of Android.

    You (and for sure your users) have to deal with it.
     
    Alexander Stolte 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