public class FileContentProvider
extends android.content.ContentProvider
In order for another application to access a file belonging to this application, you must create a "content://" URI which references that file by calling this class' createContentUriForFile() method. The other application will then use this content URI to communicate with this provider to retrieve information about that file and open an input stream to it.
If you do not want to expose your application's files to other applications, then you should set the provider's "exported" attribute to false in the "AndroidManifest.xml" file.
An instance of this class will be automatically created by the Android OS upon application startup. You should never create an instance of this class yourself.
Constructor and Description |
---|
FileContentProvider() |
Modifier and Type | Method and Description |
---|---|
static android.net.Uri |
createContentUriForFile(android.content.Context context,
File file)
Creates a "content://" URI for the given file making it accessible to other applications via this provider.
|
static android.net.Uri |
createContentUriForFile(android.content.Context context,
String filePath)
Creates a "content://" URI for the given file making it accessible to other applications via this provider.
|
int |
delete(android.net.Uri uri,
String selection,
String[] selectionArgs)
Handles a delete request from a client.
|
String |
getType(android.net.Uri uri)
Fetches the mime type of the file that the given URI references.
|
android.net.Uri |
insert(android.net.Uri uri,
android.content.ContentValues values)
Handles an insert request from a client.
|
boolean |
onCreate()
Called on application startup if registered in the "AndroidManifest.xml" file.
|
android.content.res.AssetFileDescriptor |
openAssetFile(android.net.Uri uri,
String mode)
Handles a client request to open a file belonging to this application via a file descriptor.
|
android.os.ParcelFileDescriptor |
openFile(android.net.Uri uri,
String mode)
Handles a client request to open a file belonging to this application.
|
android.database.Cursor |
query(android.net.Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
Handles query requests from clients.
|
int |
update(android.net.Uri uri,
android.content.ContentValues values,
String selection,
String[] selectionArgs)
Handles an update request from a client.
|
static void |
validateManifest(android.content.Context context)
Checks if the AndroidManifest.xml file is correctly configured for this provider.
|
public boolean onCreate()
public android.os.ParcelFileDescriptor openFile(android.net.Uri uri, String mode) throws FileNotFoundException
uri
- The URI whose file is to be opened.mode
- Access mode for the file. May be "r" for read-only access, "rw" for read and write access,
or "rwt" for read and write access that truncates any existing file.FileNotFoundException
public android.content.res.AssetFileDescriptor openAssetFile(android.net.Uri uri, String mode) throws FileNotFoundException
uri
- The URI whose file is to be opened.mode
- Access mode for the file. May be "r" for read-only access, "w" for write-only access
(erasing whatever data is currently in the file), "wa" for write-only access to append to
any existing data, "rw" for read and write access on any existing data, and "rwt" for read
and write access that truncates any existing file.FileNotFoundException
public int delete(android.net.Uri uri, String selection, String[] selectionArgs)
Not supported by this class. Calling this method will cause an exception to be thrown.
uri
- The full URI to query, including a row ID (if a specific record is requested).selection
- An optional restriction to apply to rows when deleting.public String getType(android.net.Uri uri)
uri
- The URI to query.Returns null if of an unknown type.
public android.net.Uri insert(android.net.Uri uri, android.content.ContentValues values)
Not supported by this class. Calling this method will cause an exception to be thrown.
uri
- The content:// URI of the insertion request.values
- A set of column_name/value pairs to add to the database.public android.database.Cursor query(android.net.Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
uri
- The URI to query. This will be the full URI sent by the client; if the client is requesting
a specific record, the URI will end in a record number that the implementation should parse
and add to a WHERE or HAVING clause, specifying that _id value.projection
- The list of columns to put into the cursor. If null all columns are included.selection
- A selection criteria to apply when filtering rows. If null then all rows are included.selectionArgs
- You may include ?s in selection, which will be replaced by the values from selectionArgs,
in order that they appear in the selection. The values will be bound as Strings.sortOrder
- How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.public int update(android.net.Uri uri, android.content.ContentValues values, String selection, String[] selectionArgs)
uri
- The URI to query. This can potentially have a record ID if this is an update request for a specific record.values
- A Bundle mapping from column names to new column values (NULL is a valid value).selection
- An optional filter to match rows to update.public static void validateManifest(android.content.Context context)
Will throw an exception if the manifest is missing this provider or if its "authorities" attribute is misconfigured.
This method is only expected to be called by the CoronaActivity class.
context
- Context needed to access this application's manifest settings. Cannot be null.public static android.net.Uri createContentUriForFile(android.content.Context context, File file)
context
- A reference to this application's context.
Needed to fetch this application's package name. Cannot be null.file
- The file to create a content URI for.
If this file is set to a relative path, then this method will treat it as an asset file within the APK's "assets" directory or within the Google Play expansion file.
Cannot be null or else an exception will be thrown.
public static android.net.Uri createContentUriForFile(android.content.Context context, String filePath)
context
- A reference to this application's context.
Needed to fetch this application's package name. Cannot be null.filePath
- A relative or absolute path to a file belonging to this application.
If this file is set to a relative path, then this method will treat it as an asset file within the APK's "assets" directory or within the Google Play expansion file.
An exception will be thrown if set to null or empty string.