Android Question Subdirectories in File.DirInternal?

Discussion in 'Android Questions' started by Troberg, Apr 15, 2015.

  1. Troberg

    Troberg Well-Known Member Licensed User

    Is there a way to package files so that they end up in subdirectories of File.DirInternal?

    Example:

    File.DirInternal/Languages/English.lng
    File.DirInternal/ColorSchemes/Red.sch

    And, of course, I messed up when writing the post. It should be File.DirAssets, of course.
     
    Last edited: Apr 15, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes. It is possible. You will need to use lower cased names for the folders and files.
     
    Troberg likes this.
  3. Troberg

    Troberg Well-Known Member Licensed User

    OK, I can live with lowercase, but how do I get the subdirectories in File.DirAssets and the files in the subdirs?
     
  4. JoanRPM

    JoanRPM Active Member Licensed User

    For expample, I load a bmp (in help directory) like this:

    Code:
    Dim Bitmap1 As Bitmap
    Dim imvT1 As ImageView
    Bitmap1.Initialize(
    File.DirAssets,"help/t1.png")    'ignore
    imvT1.Initialize("")
    imvT1.Bitmap = Bitmap1
    Activity.AddView(imvT1,262dip,51dip+90dip,3dip,145dip)
     
    Troberg likes this.
  5. Troberg

    Troberg Well-Known Member Licensed User

    Loading it is not the problem, how do I add the file to the project so that it ends up in a subdirectory? I can't find a way to define the dir structure for DirAssets.
     
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    In your B4A project there is a 'Files' directory. You can make the structure there, and it will be included in the apk.
    It wont show up in the Files tab in the IDE.
     
    lemonisdead, Troberg and NJDude like this.
  7. Troberg

    Troberg Well-Known Member Licensed User

    Ah, it was that easy...

    Do I also have to include the files in the IDE, or is the entire Files dir included automatically?
     
  8. thedesolatesoul

    thedesolatesoul Expert Licensed User

    I believe the entire Files folder is included so be careful not to put any junk in it.
     
    Troberg, lemonisdead and NJDude like this.
  9. NJDude

    NJDude Expert Licensed User

    Yes, any files or directories in the FILES folder gets added to the APK, that directory should only contain the files pertaining to the app and nothing else.
     
  10. Troberg

    Troberg Well-Known Member Licensed User

    Thanks, that trimmed down the size of my APK! My image editor saves backup copies of the files as you work on them...
     
  11. Troberg

    Troberg Well-Known Member Licensed User

    Nope, didn't work. I just tried it, and only files directly in the Files folder where included, not subdirectories or files in them.

    Example:

    Info.png exists in both Files/ and Files/Icons/. Presumably, both should then be on the device.

    Code:
    'Works
    bm.Initialize(File.DirAssets, "info.png")

    'Doesn't work
    bm.Initialize(File.DirAssets & "/icons""info.png")
     
  12. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Is the folder lower case in the Files directory? "Icons" or "icons"? Use lowercase filenames. It definitely works.
    Sometimes Windows plays tricks on you, so renaming doesnt work, you might have to delete the folder and recreate it.
     
    NJDude and Troberg like this.
  13. Troberg

    Troberg Well-Known Member Licensed User

    It looks like lowercase, but I'll recreate it and see. Likewise, I'll check the names from the command line.
     
  14. Troberg

    Troberg Well-Known Member Licensed User

    Found the problem. Apparently, File.DirAssets doesn't work like a normal dir. Changing the code to this helped:

    Code:
    bm.Initialize(File.DirAssets, "icons/" & IconFileName)
    In other words, the dir seems to be part of the filename, instead of the path.
     
  15. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Interesting. I usually use File.Combine to concatenate any paths rather than an '&'.
     
    NJDude, DonManfred and Troberg like 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