android.support.v4.content
Class FileProvider
java.lang.Object
android.content.ContentProvider
android.support.v4.content.FileProvider
- All Implemented Interfaces:
- android.content.ComponentCallbacks, android.content.ComponentCallbacks2
public class FileProvider
- extends android.content.ContentProvider
Provider to support easy sharing of private files between apps. When paired
with features like Context.grantUriPermission(String, Uri, int)
or
Intent.FLAG_GRANT_READ_URI_PERMISSION
, this provider ensures that
receiving apps can always open the underlying file.
Apps should generally avoid sending raw filesystem paths across process
boundaries, since the receiving app may not have the same access as the
sender. Instead, apps should send Uri
backed by a provider like
FileProvider
.
To use this provider, add it to your manifest:
And define one or more filesystem paths your provider should support in an
XML resource. This provider will only support files which exist under these
defined paths.
Then use getUriForFile(Context, String, File)
at runtime to generate
a Uri
backed by the provider. Since the provider is not exported,
these Uri
can only be accessed by other apps when you explicitly
grant access.
Nested classes/interfaces inherited from class android.content.ContentProvider |
android.content.ContentProvider.PipeDataWriter<T> |
Fields inherited from interface android.content.ComponentCallbacks2 |
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN |
Method Summary |
void |
attachInfo(android.content.Context context,
android.content.pm.ProviderInfo info)
|
int |
delete(android.net.Uri uri,
String selection,
String[] selectionArgs)
|
String |
getType(android.net.Uri uri)
|
static android.net.Uri |
getUriForFile(android.content.Context context,
String authority,
File file)
Return a Uri that provides access to the given File . |
android.net.Uri |
insert(android.net.Uri uri,
android.content.ContentValues values)
|
boolean |
onCreate()
|
android.os.ParcelFileDescriptor |
openFile(android.net.Uri uri,
String mode)
|
android.database.Cursor |
query(android.net.Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
|
int |
update(android.net.Uri uri,
android.content.ContentValues values,
String selection,
String[] selectionArgs)
|
Methods inherited from class android.content.ContentProvider |
applyBatch, bulkInsert, call, getContext, getPathPermissions, getReadPermission, getStreamTypes, getWritePermission, isTemporary, onConfigurationChanged, onLowMemory, onTrimMemory, openAssetFile, openFileHelper, openPipeHelper, openTypedAssetFile, query, setPathPermissions, setReadPermission, setWritePermission, shutdown |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FileProvider
public FileProvider()
onCreate
public boolean onCreate()
- Specified by:
onCreate
in class android.content.ContentProvider
attachInfo
public void attachInfo(android.content.Context context,
android.content.pm.ProviderInfo info)
- Overrides:
attachInfo
in class android.content.ContentProvider
getUriForFile
public static android.net.Uri getUriForFile(android.content.Context context,
String authority,
File file)
- Return a
Uri
that provides access to the given File
. The
returned Uri
can be used with features like
Context.grantUriPermission(String, Uri, int)
or
Intent.FLAG_GRANT_READ_URI_PERMISSION
to allow other apps to
access private files. Providers only support files which exist under
filesystem paths defined in their <meta-data>
.
- Parameters:
authority
- The authority of a FileProvider
defined as a
<provider>
in your manifest.
- Throws:
IllegalArgumentException
- When the given File
is outside
the paths supported by the provider.
query
public android.database.Cursor query(android.net.Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder)
- Specified by:
query
in class android.content.ContentProvider
getType
public String getType(android.net.Uri uri)
- Specified by:
getType
in class android.content.ContentProvider
insert
public android.net.Uri insert(android.net.Uri uri,
android.content.ContentValues values)
- Specified by:
insert
in class android.content.ContentProvider
update
public int update(android.net.Uri uri,
android.content.ContentValues values,
String selection,
String[] selectionArgs)
- Specified by:
update
in class android.content.ContentProvider
delete
public int delete(android.net.Uri uri,
String selection,
String[] selectionArgs)
- Specified by:
delete
in class android.content.ContentProvider
openFile
public android.os.ParcelFileDescriptor openFile(android.net.Uri uri,
String mode)
throws FileNotFoundException
- Overrides:
openFile
in class android.content.ContentProvider
- Throws:
FileNotFoundException
Copyright © 2013 Marek Kedzierski. All Rights Reserved.