AssetsContentProvider

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.

Preparing assets

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"
    }
}

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open fun delete(@NonNull uri: Uri, s: String, strings: Array<String>): Int
Link copied to clipboard
open fun getAuthority(@NonNull context: Context): Uri
Returns an Uri containing the scheme and authority of this content provider.
Link copied to clipboard
open fun getType(@NonNull uri: Uri): String
Link copied to clipboard
open fun insert(@NonNull uri: Uri, contentValues: ContentValues): Uri
Link copied to clipboard
open fun onCreate(): Boolean
Link copied to clipboard
Link copied to clipboard
open fun query(@NonNull uri: Uri, strings: Array<String>, s: String, strings1: Array<String>, s1: String): Cursor
Link copied to clipboard
open fun update(@NonNull uri: Uri, contentValues: ContentValues, s: String, strings: Array<String>): Int