Class AssetsContentProvider

  • All Implemented Interfaces:
    android.content.ComponentCallbacks , android.content.ComponentCallbacks2

    
    public class AssetsContentProvider
    extends ContentProvider
                        

    A content provider that serves files from the app's assets.

    This content provider is registered inside the app's manifest through manifest merging (you don't need to do this manually). The content provider is not exported, so it is not possible for other apps to access the assets.

    The providers base URI is content://{$applicationId}{ CONTENT_PROVIDER_AUTHORITY_SUFFIX}. All asset paths are relative to this URI. If you would like to serve a file videos/movie.mp4 the respective URI would be content://{$applicationId}{CONTENT_PROVIDER_AUTHORITY_SUFFIX}/videos/movie.mp4.

    This content provider may only serve uncompressed asset files (caused by a limitation of Android's AssetManager). If you try to access a compressed asset the content provider will throw a FileNotFoundException.

    By default the aapt tool will compress all files inside the assets/ folder of your app before copying them to the APK. The only exception for this are files that are already compressed like multimedia files (i.e. video and audio files).

    You can disable compression for arbitrary file types by adding this to your build.gradle script:

    
    android {
        aaptOptions {
            // You can also specify other types, even a list of types.
            noCompress "txt"
        }
    }