Search code examples
androidandroid-webviewandroid-assets

Writing to android assets directory at runtime?


I get html snippets updates from a network request and need to insert them into a local html file that can then be fetched with webView.loadUrl at runtime.

I can easily load the file from /android_assets/myFile.html using webView.loadUrl, but I cannot write to the file because the /android_assets directory is not accessible at runtime: Writing to /android_assets at runtime

So my question is, is there another location I can place the myFile.html so I can write to it at runtime and load it into the webView too?


Solution

  • The asset directory is read only, you can not change it dynamically.
    You can read & white files in the flowing directories:

    Context.getFilesDir()  
    

    No permission required
    Typical position: /data/data/app.package.name/files/

    Context.getExternalFilesDir(null)  
    

    Requires WRITE_EXTERNAL_STORAGE when api level <= 18
    Typical position: /sdcard/Android/data/app.package.name/files/

    Environment.getExternalStorageDirectory()  
    

    Requires WRITE_EXTERNAL_STORAGE
    Typical position: /sdcard/