How to access assets folder in my android app?

前端 未结 3 1991
抹茶落季
抹茶落季 2021-01-13 12:36

I\'m writing at a little project for a friend. A notecard application. My plan is to put the notecards in an xml format so i can import and export them easily. I located the

相关标签:
3条回答
  • 2021-01-13 13:28

    Zip your xml folder (xml.zip for example) and put it in assets. Getting assets with AssetsManager is very slow. Also, doing so you can maintain your directory structure and just copy it to sdcard and extract it there. This will be a lot faster than getting each file in the directory. You can use this post for the unzipping: How to unzip files programmatically in Android?. Hope this helps.

    0 讨论(0)
  • 2021-01-13 13:28

    Assets should be in the root of the folder... cannot put file in a sub folder. assets\file.suf would work while assets\sub\file.suf would not

    0 讨论(0)
  • 2021-01-13 13:29
    android.resource://packagename/assets/filename
    

    you can use the above line to refer to a file in assets folder. Just replace the package name and file name.

    Note file name must not contain extensions

    Updated::

    private List<String> getFiles(){
     AssetManager assetManager = getAssets();
        List<String> files = null;
        try {
            files = assetManager.list("");
        } catch (IOException e) {
            Log.e("tag", e.getMessage());
        }
    } 
    
    0 讨论(0)
提交回复
热议问题