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 filevideos/movie.mp4
the respective URI would becontent://{$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 theassets/
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" } }
-
-
Constructor Summary
Constructors Constructor Description AssetsContentProvider()
-
Method Summary
Modifier and Type Method Description static Uri
getAuthority(@NonNull() Context context)
Returns an Uri containing the scheme and authority of this content provider. boolean
onCreate()
Cursor
query(@NonNull() Uri uri, Array<String> strings, String s, Array<String> strings1, String s1)
String
getType(@NonNull() Uri uri)
Uri
insert(@NonNull() Uri uri, ContentValues contentValues)
int
delete(@NonNull() Uri uri, String s, Array<String> strings)
int
update(@NonNull() Uri uri, ContentValues contentValues, String s, Array<String> strings)
AssetFileDescriptor
openAssetFile(@NonNull() Uri uri, @NonNull() String mode)
-
-
Method Detail
-
getAuthority
@NonNull() static Uri getAuthority(@NonNull() Context context)
Returns an Uri containing the scheme and authority of this content provider.
- Parameters:
context
- Context required for building the authority.
-
onCreate
boolean onCreate()
-
query
Cursor query(@NonNull() Uri uri, Array<String> strings, String s, Array<String> strings1, String s1)
-
insert
Uri insert(@NonNull() Uri uri, ContentValues contentValues)
-
openAssetFile
AssetFileDescriptor openAssetFile(@NonNull() Uri uri, @NonNull() String mode)
-
-
-
-