# FileProvider

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/FileProvider.java+class:androidx.core.content.FileProvider) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

<br />

```
public class FileProvider extends ContentProvider
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [android.content.ContentProvider](https://developer.android.com/reference/android/content/ContentProvider.html) ||
|   | ↳ | [androidx.core.content.FileProvider](https://developer.android.com/reference/androidx/core/content/FileProvider) |

*** ** * ** ***

FileProvider is a special subclass of `https://developer.android.com/reference/android/content/ContentProvider.html` that facilitates secure sharing of files associated with an app by creating a `content://``https://developer.android.com/reference/android/net/Uri.html` for a file instead of a `file:///``https://developer.android.com/reference/android/net/Uri.html`.

A content URI allows you to grant read and write access using temporary access permissions. When you create an `https://developer.android.com/reference/android/content/Intent.html` containing a content URI, in order to send the content URI to a client app, you can also call `https://developer.android.com/reference/android/content/Intent.html#setFlags(int)` to add permissions. These permissions are available to the client app for as long as the stack for a receiving `https://developer.android.com/reference/android/app/Activity.html` is active. For an `https://developer.android.com/reference/android/content/Intent.html` going to a `https://developer.android.com/reference/android/app/Service.html`, the permissions are available as long as the `https://developer.android.com/reference/android/app/Service.html` is running.

In comparison, to control access to a `file:///``https://developer.android.com/reference/android/net/Uri.html` you have to modify the file system permissions of the underlying file. The permissions you provide become available to *any* app, and remain in effect until you change them. This level of access is fundamentally insecure.

The increased level of file access security offered by a content URI makes FileProvider a key part of Android's security infrastructure.

This overview of FileProvider includes the following topics:

1. Defining a FileProvider
2. Specifying Available Files
3. Generating the Content URI for a File
4. Granting Temporary Permissions to a URI
5. Serving a Content URI to Another App

**Defining a FileProvider**

Extend FileProvider with a default constructor:

```
public class MyFileProvider extends FileProvider {
   public MyFileProvider() {
       ...
   }
}
```
Add a `https://developer.android.com/guide/topics/manifest/provider-element` element to your app manifest. Set the `android:name` attribute to the FileProvider you created. Set the `android:authorities` attribute to a URI authority based on a domain you control; for example, if you control the domain `mydomain.com` you should use the authority `com.mydomain.fileprovider`. Set the `android:exported` attribute to `false`; the FileProvider does not need to be public. Set the [android:grantUriPermissions](https://developer.android.com/guide/topics/manifest/provider-element#gprmsn) attribute to `true`, to allow you to grant temporary access to files. For example:

```
<manifest>
   ...
   <application>
       ...
       <provider
           android:name="com.sample.MyFileProvider"
           android:authorities="com.mydomain.fileprovider"
           android:exported="false"
           android:grantUriPermissions="true">
           ...
       </provider>
       ...
   </application>
</manifest>
```

It is possible to use FileProvider directly instead of extending it. However, this is not reliable and will causes crashes on some devices.

**Specifying Available Files**

A FileProvider can only generate a content URI for files in directories that you specify beforehand. To specify a directory, specify its storage area and path in XML, using child elements of the `<paths>` element. For example, the following `paths` element tells FileProvider that you intend to request content URIs for the `images/` subdirectory of your private file area.

```
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <files-path name="my_images" path="images/"/>
   ...
</paths>
```

The `<paths>` element must contain one or more of the following child elements:

-

  ```
  <files-path name="name" path="path" />
  ```
  Represents files in the `files/` subdirectory of your app's internal storage area. This subdirectory is the same as the value returned by `https://developer.android.com/reference/android/content/Context.html#getFilesDir()`.
-

  ```
  <cache-path name="name" path="path" />
  ```
  Represents files in the cache subdirectory of your app's internal storage area. The root path of this subdirectory is the same as the value returned by `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`.
-

  ```
  <external-path name="name" path="path" />
  ```
  Represents files in the root of the external storage area. The root path of this subdirectory is the same as the value returned by `https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()`.
-

  ```
  <external-files-path name="name" path="path"
  />
  ```
  Represents files in the root of your app's external storage area. The root path of this subdirectory is the same as the value returned by `https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)`.
-

  ```
  <external-cache-path name="name" path="path"
  />
  ```
  Represents files in the root of your app's external cache area. The root path of this subdirectory is the same as the value returned by `https://developer.android.com/reference/android/content/Context.html#getExternalCacheDir()`.
-

  ```
  <external-media-path name="name" path="path"
  />
  ```
  Represents files in the root of your app's external media area. The root path of this subdirectory is the same as the value returned by the first result of `https://developer.android.com/reference/android/content/Context.html#getExternalMediaDirs()`.

These child elements all use the same attributes:

- `name="name"`

  A URI path segment. To enforce security, this value hides the name of the subdirectory you're sharing. The subdirectory name for this value is contained in the `path` attribute.
- `path="path"`

  The subdirectory you're sharing. While the `name` attribute is a URI path segment, the `path` value is an actual subdirectory name. Notice that the value refers to a **subdirectory**, not an individual file or files. You can't share a single file by its file name, nor can you specify a subset of files using wildcards.

You must specify a child element of `<paths>` for each directory that contains files for which you want content URIs. For example, these XML elements specify two directories:

```
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <files-path name="my_images" path="images/"/>
   <files-path name="my_docs" path="docs/"/>
</paths>
```

Put the `<paths>` element and its children in an XML file in your project. For example, you can add them to a new file called `res/xml/file_paths.xml`. To link this file to the FileProvider, pass it to super() in the constructor for the FileProvider you defined above, add a [](https://developer.android.com/guide/topics/manifest/meta-data
-element) element as a child of the `<provider>` element that defines the FileProvider. Set the `<meta-data>` element's "android:name" attribute to `android.support.FILE_PROVIDER_PATHS`. Set the element's "android:resource" attribute to `@xml/file_paths` (notice that you don't specify the `.xml` extension). For example:

```
 <provider 
 android:name="com.sample.MyFileProvider" 
 android:authorities="com.mydomain.fileprovider" 
 android:exported="false" 
 android:grantUriPermissions="true"> 
 <meta-data 
 android:name="android.support.FILE_PROVIDER_PATHS" 
 android:resource="@xml/file_paths" /> 
 </provider> 
 
```

**Generating the Content URI for a File**

To share a file with another app using a content URI, your app has to generate the content URI. To generate the content URI, create a new `https://developer.android.com/reference/java/io/File.html` for the file, then pass the `https://developer.android.com/reference/java/io/File.html` to `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. You can send the content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)` to another app in an `https://developer.android.com/reference/android/content/Intent.html`. The client app that receives the content URI can open the file and access its contents by calling `https://developer.android.com/reference/android/content/ContentResolver.html#openFileDescriptor(android.net.Uri, java.lang.String)` to get a `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html`.

For example, suppose your app is offering files to other apps with a FileProvider that has the authority `com.mydomain.fileprovider`. To get a content URI for the file `default_image.jpg` in the `images/` subdirectory of your internal storage add the following code:

```
 File imagePath = new File(Context.getFilesDir(), "my_images"); 
 File newFile = new File(imagePath, "default_image.jpg"); 
 Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile); 
 
```
As a result of the previous snippet, `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)` returns the content URI `content://com.mydomain.fileprovider/my_images/default_image.jpg`.

**Granting Temporary Permissions to a URI**

To grant an access permission to a content URI returned from `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`, you can either grant the permission to a specific package or include the permission in an intent, as shown in the following sections.

#### Grant Permission to a Specific Package

Call the method `https://developer.android.com/reference/android/content/Context.html#grantUriPermission(java.lang.String, android.net.Uri, int)` for the `content://``https://developer.android.com/reference/android/net/Uri.html`, using the desired mode flags. This grants temporary access permission for the content URI to the specified package, according to the value of the the `mode_flags` parameter, which you can set to `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_READ_URI_PERMISSION`, `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_WRITE_URI_PERMISSION` or both. The permission remains in effect until you revoke it by calling `https://developer.android.com/reference/android/content/Context.html#revokeUriPermission(android.net.Uri, int)` or until the device reboots.

#### Include the Permission in an Intent

To allow the user to choose which app receives the intent, and the permission to access the content, do the following:

1. Put the content URI in an `https://developer.android.com/reference/android/content/Intent.html` by calling `https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)`.
2. Call the method `https://developer.android.com/reference/android/content/Intent.html#setFlags(int)` with either `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_READ_URI_PERMISSION` or `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_WRITE_URI_PERMISSION` or both.

   To support devices that run a version between Android 4.1 (API level 16) and Android 5.1 (API level 22) inclusive, create a `https://developer.android.com/reference/android/content/ClipData.html` object from the content URI, and set the access permissions on the `ClipData` object:

   ```
    shareContentIntent.setClipData(ClipData.newRawUri("", contentUri)); 
    shareContentIntent.addFlags( 
    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 
    
   ```
3. Send the `https://developer.android.com/reference/android/content/Intent.html` to another app. Most often, you do this by calling `https://developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent)`.

Permissions granted in an `https://developer.android.com/reference/android/content/Intent.html` remain in effect while the stack of the receiving `https://developer.android.com/reference/android/app/Activity.html` is active. When the stack finishes, the permissions are automatically removed. Permissions granted to one `https://developer.android.com/reference/android/app/Activity.html` in a client app are automatically extended to other components of that app.

**Serving a Content URI to Another App**

There are a variety of ways to serve the content URI for a file to a client app. One common way is for the client app to start your app by calling `https://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int, android.os.Bundle)`, which sends an `https://developer.android.com/reference/android/content/Intent.html` to your app to start an `https://developer.android.com/reference/android/app/Activity.html` in your app. In response, your app can immediately return a content URI to the client app or present a user interface that allows the user to pick a file. In the latter case, once the user picks the file your app can return its content URI. In both cases, your app returns the content URI in an `https://developer.android.com/reference/android/content/Intent.html` sent via `https://developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent)`.

You can also put the content URI in a `https://developer.android.com/reference/android/content/ClipData.html` object and then add the object to an `https://developer.android.com/reference/android/content/Intent.html` you send to a client app. To do this, call `https://developer.android.com/reference/android/content/Intent.html#setClipData(android.content.ClipData)`. When you use this approach, you can add multiple `https://developer.android.com/reference/android/content/ClipData.html` objects to the `https://developer.android.com/reference/android/content/Intent.html`, each with its own content URI. When you call `https://developer.android.com/reference/android/content/Intent.html#setFlags(int)` on the `https://developer.android.com/reference/android/content/Intent.html` to set temporary access permissions, the same permissions are applied to all of the content URIs.

**Note:** The `https://developer.android.com/reference/android/content/Intent.html#setClipData(android.content.ClipData)` method is only available in platform version 16 (Android 4.1) and later. If you want to maintain compatibility with previous versions, you should send one content URI at a time in the `https://developer.android.com/reference/android/content/Intent.html`. Set the action to `https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND` and put the URI in data by calling `https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)`.
**More Information**

To learn more about FileProvider, see the Android training class [Sharing Files Securely with URIs](https://developer.android.com/training/secure-file-sharing).

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/content/FileProvider#FileProvider()()` |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/core/content/FileProvider#FileProvider(int)(@https://developer.android.com/reference/androidx/annotation/XmlRes int resourceId)` |

| ### Public methods |
|---|---|
| `void` | `@https://developer.android.com/reference/androidx/annotation/CallSuper https://developer.android.com/reference/androidx/core/content/FileProvider#attachInfo(android.content.Context,android.content.pm.ProviderInfo)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/pm/ProviderInfo.html info)` After the FileProvider is instantiated, this method is called to provide the system with information about the provider. |
| `int` | `https://developer.android.com/reference/androidx/core/content/FileProvider#delete(android.net.Uri,java.lang.String,java.lang.String[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html selection, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] selectionArgs )` Deletes the file associated with the specified content URI, as returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#getType(android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri)` Returns the MIME type of a content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#getTypeAnonymous(android.net.Uri)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri)` Unrestricted version of getType called, when caller does not have corresponding permissions |
| `static https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file )` Return a content URI for a given `https://developer.android.com/reference/java/io/File.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html displayName )` Return a content URI for a given `https://developer.android.com/reference/java/io/File.html`. |
| `https://developer.android.com/reference/android/net/Uri.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#insert(android.net.Uri,android.content.ContentValues)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentValues.html values)` By default, this method throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html`. |
| `boolean` | `https://developer.android.com/reference/androidx/core/content/FileProvider#onCreate()()` The default FileProvider implementation does not need to be initialized. |
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#openFile(android.net.Uri,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html mode)` By default, FileProvider automatically returns the `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` for a file associated with a `content://``https://developer.android.com/reference/android/net/Uri.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/database/Cursor.html` | `https://developer.android.com/reference/androidx/core/content/FileProvider#query(android.net.Uri,java.lang.String[],java.lang.String,java.lang.String[],java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] projection, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html selection, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] selectionArgs, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html sortOrder )` Use a content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)` to get information about a file managed by the FileProvider. |
| `int` | `https://developer.android.com/reference/androidx/core/content/FileProvider#update(android.net.Uri,android.content.ContentValues,java.lang.String,java.lang.String[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ContentValues.html values, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html selection, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] selectionArgs )` By default, this method throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html`. |

### Inherited Constants

From [android.content.ComponentCallbacks2](https://developer.android.com/reference/android/content/ComponentCallbacks2.html) `static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_BACKGROUND = 40` `static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_COMPLETE = 80`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_MODERATE = 60`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_RUNNING_CRITICAL = 15`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_RUNNING_LOW = 10`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_RUNNING_MODERATE = 5`

**This field is deprecated.**
`static final int` `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#TRIM_MEMORY_UI_HIDDEN = 20`

### Inherited methods

From [android.content.ContentProvider](https://developer.android.com/reference/android/content/ContentProvider.html) `ContentProviderResult[]` `https://developer.android.com/reference/android/content/ContentProvider.html#applyBatch(java.lang.String, java.util.ArrayList&lt;android.content.ContentProviderOperation&gt;)(

https://developer.android.com/reference/java/lang/String.html authority,

https://developer.android.com/reference/java/util/ArrayList.html<https://developer.android.com/reference/android/content/ContentProviderOperation.html> operations

)` `int` `https://developer.android.com/reference/android/content/ContentProvider.html#bulkInsert(android.net.Uri, android.content.ContentValues[])(https://developer.android.com/reference/android/net/Uri.html uri, ContentValues[] values)` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/content/ContentProvider.html#call(java.lang.String, java.lang.String, android.os.Bundle)(https://developer.android.com/reference/java/lang/String.html method, https://developer.android.com/reference/java/lang/String.html arg, https://developer.android.com/reference/android/os/Bundle.html extras)` `https://developer.android.com/reference/android/net/Uri.html` `https://developer.android.com/reference/android/content/ContentProvider.html#canonicalize(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html url)` `final https://developer.android.com/reference/android/content/ContentProvider.CallingIdentity.html` `https://developer.android.com/reference/android/content/ContentProvider.html#clearCallingIdentity()()` `int` `https://developer.android.com/reference/android/content/ContentProvider.html#delete(android.net.Uri, android.os.Bundle)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/android/os/Bundle.html extras)` `void` `https://developer.android.com/reference/android/content/ContentProvider.html#dump(java.io.FileDescriptor, java.io.PrintWriter, java.lang.String[])(https://developer.android.com/reference/java/io/FileDescriptor.html fd, https://developer.android.com/reference/java/io/PrintWriter.html writer, String[] args)` `final https://developer.android.com/reference/android/content/AttributionSource.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getCallingAttributionSource()()` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getCallingAttributionTag()()` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getCallingPackage()()` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getCallingPackageUnchecked()()` `final https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getContext()()` `final PathPermission[]` `https://developer.android.com/reference/android/content/ContentProvider.html#getPathPermissions()()` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getReadPermission()()` `String[]` `https://developer.android.com/reference/android/content/ContentProvider.html#getStreamTypes(android.net.Uri, java.lang.String)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/java/lang/String.html mimeTypeFilter)` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/ContentProvider.html#getWritePermission()()` `boolean` `https://developer.android.com/reference/android/content/ContentProvider.html#isTemporary()()` `void` `https://developer.android.com/reference/android/content/ContentProvider.html#onCallingPackageChanged()()` `void` `https://developer.android.com/reference/android/content/ContentProvider.html#onConfigurationChanged(android.content.res.Configuration)(https://developer.android.com/reference/android/content/res/Configuration.html newConfig)` `void` `https://developer.android.com/reference/android/content/ContentProvider.html#onLowMemory()()`

**This method is deprecated.**
`void` `https://developer.android.com/reference/android/content/ContentProvider.html#onTrimMemory(int)(int level)` `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` `https://developer.android.com/reference/android/content/ContentProvider.html#openAssetFile(android.net.Uri, java.lang.String)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/java/lang/String.html mode)` `final https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` `https://developer.android.com/reference/android/content/ContentProvider.html#openFileHelper(android.net.Uri, java.lang.String)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/java/lang/String.html mode)` `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` `<T> https://developer.android.com/reference/android/content/ContentProvider.html#openPipeHelper(android.net.Uri, java.lang.String, android.os.Bundle, T, android.content.ContentProvider.PipeDataWriter&lt;T&gt;)(

https://developer.android.com/reference/android/net/Uri.html uri,

https://developer.android.com/reference/java/lang/String.html mimeType,

https://developer.android.com/reference/android/os/Bundle.html opts,

T args,

https://developer.android.com/reference/android/content/ContentProvider.PipeDataWriter.html<T> func

)` `https://developer.android.com/reference/android/content/res/AssetFileDescriptor.html` `https://developer.android.com/reference/android/content/ContentProvider.html#openTypedAssetFile(android.net.Uri, java.lang.String, android.os.Bundle)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/java/lang/String.html mimeTypeFilter, https://developer.android.com/reference/android/os/Bundle.html opts)` `https://developer.android.com/reference/android/database/Cursor.html` `https://developer.android.com/reference/android/content/ContentProvider.html#query(android.net.Uri, java.lang.String[], android.os.Bundle, android.os.CancellationSignal)(

https://developer.android.com/reference/android/net/Uri.html uri,

String[] projection,

https://developer.android.com/reference/android/os/Bundle.html queryArgs,

https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal

)` `boolean` `https://developer.android.com/reference/android/content/ContentProvider.html#refresh(android.net.Uri, android.os.Bundle, android.os.CancellationSignal)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/android/os/Bundle.html extras, https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal)` `final https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/content/ContentProvider.html#requireContext()()` `final void` `https://developer.android.com/reference/android/content/ContentProvider.html#restoreCallingIdentity(android.content.ContentProvider.CallingIdentity)(https://developer.android.com/reference/android/content/ContentProvider.CallingIdentity.html identity)` `final void` `https://developer.android.com/reference/android/content/ContentProvider.html#setPathPermissions(android.content.pm.PathPermission[])(PathPermission[] permissions)` `final void` `https://developer.android.com/reference/android/content/ContentProvider.html#setReadPermission(java.lang.String)(https://developer.android.com/reference/java/lang/String.html permission)` `final void` `https://developer.android.com/reference/android/content/ContentProvider.html#setWritePermission(java.lang.String)(https://developer.android.com/reference/java/lang/String.html permission)` `void` `https://developer.android.com/reference/android/content/ContentProvider.html#shutdown()()` `https://developer.android.com/reference/android/net/Uri.html` `https://developer.android.com/reference/android/content/ContentProvider.html#uncanonicalize(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html url)` `int` `https://developer.android.com/reference/android/content/ContentProvider.html#update(android.net.Uri, android.content.ContentValues, android.os.Bundle)(https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/android/content/ContentValues.html values, https://developer.android.com/reference/android/os/Bundle.html extras)`

## Public constructors

### FileProvider

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public FileProvider()
```

## Protected constructors

### FileProvider

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
protected FileProvider(@XmlRes int resourceId)
```

## Public methods

### attachInfo

```
@CallSuper
public void attachInfo(@NonNull Context context, @NonNull ProviderInfo info)
```

After the FileProvider is instantiated, this method is called to provide the system with information about the provider.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html` for the current component. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/pm/ProviderInfo.html info` | A `https://developer.android.com/reference/android/content/pm/ProviderInfo.html` for the new provider. |

### delete

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public int delete(
    @NonNull Uri uri,
    @Nullable String selection,
    @Nullable String[] selectionArgs
)
```

Deletes the file associated with the specified content URI, as returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. Notice that this method does **not** throw an `https://developer.android.com/reference/java/io/IOException.html`; you must check its return value.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | A content URI for a file, as returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html selection` | Ignored. Set to `null`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] selectionArgs` | Ignored. Set to `null`. |

| Returns |
|---|---|
| `int` | 1 if the delete succeeds; otherwise, 0. |

### getType

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public @Nullable String getType(@NonNull Uri uri)
```

Returns the MIME type of a content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | A content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | If the associated file has an extension, the MIME type associated with that extension; otherwise `application/octet-stream`. |

### getTypeAnonymous

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

```
public @Nullable String getTypeAnonymous(@NonNull Uri uri)
```

Unrestricted version of getType called, when caller does not have corresponding permissions

### getUriForFile

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static Uri getUriForFile(
    @NonNull Context context,
    @NonNull String authority,
    @NonNull File file
)
```

Return a content URI for a given `https://developer.android.com/reference/java/io/File.html`. Specific temporary permissions for the content URI can be set with `https://developer.android.com/reference/android/content/Context.html#grantUriPermission(java.lang.String, android.net.Uri, int)`, or added to an `https://developer.android.com/reference/android/content/Intent.html` by calling `https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)` and then `https://developer.android.com/reference/android/content/Intent.html#setFlags(int)`; in both cases, the applicable flags are `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_READ_URI_PERMISSION` and `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_WRITE_URI_PERMISSION`. A FileProvider can only return a `content``https://developer.android.com/reference/android/net/Uri.html` for file paths defined in their `<paths>` meta-data element. See the Class Overview for more information.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html` for the current component. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority` | The authority of a `https://developer.android.com/reference/androidx/core/content/FileProvider` defined in a `<provider>` element in your app's manifest. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file` | A `https://developer.android.com/reference/java/io/File.html` pointing to the filename for which you want a `content``https://developer.android.com/reference/android/net/Uri.html`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/net/Uri.html` | A content URI for the file. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | When the given `https://developer.android.com/reference/java/io/File.html` is outside the paths supported by the provider. |

### getUriForFile

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)

```
public static @NonNull Uri getUriForFile(
    @NonNull Context context,
    @NonNull String authority,
    @NonNull File file,
    @NonNull String displayName
)
```

Return a content URI for a given `https://developer.android.com/reference/java/io/File.html`. Specific temporary permissions for the content URI can be set with `https://developer.android.com/reference/android/content/Context.html#grantUriPermission(java.lang.String, android.net.Uri, int)`, or added to an `https://developer.android.com/reference/android/content/Intent.html` by calling `https://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)` and then `https://developer.android.com/reference/android/content/Intent.html#setFlags(int)`; in both cases, the applicable flags are `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_READ_URI_PERMISSION` and `https://developer.android.com/reference/android/content/Intent.html#FLAG_GRANT_WRITE_URI_PERMISSION`. A FileProvider can only return a `content``https://developer.android.com/reference/android/net/Uri.html` for file paths defined in their `<paths>` meta-data element. See the Class Overview for more information.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html` for the current component. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html authority` | The authority of a `https://developer.android.com/reference/androidx/core/content/FileProvider` defined in a `<provider>` element in your app's manifest. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file` | A `https://developer.android.com/reference/java/io/File.html` pointing to the filename for which you want a `content``https://developer.android.com/reference/android/net/Uri.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html displayName` | The filename to be displayed. This can be used if the original filename is undesirable. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html` | A content URI for the file. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | When the given `https://developer.android.com/reference/java/io/File.html` is outside the paths supported by the provider. |

### insert

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public Uri insert(@NonNull Uri uri, @NonNull ContentValues values)
```

By default, this method throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html`. You must subclass FileProvider if you want to provide different functionality.

### onCreate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public boolean onCreate()
```

The default FileProvider implementation does not need to be initialized. If you want to override this method, you must provide your own subclass of FileProvider.

### openFile

```
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)
```

By default, FileProvider automatically returns the `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` for a file associated with a `content://``https://developer.android.com/reference/android/net/Uri.html`. To get the `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html`, call `https://developer.android.com/reference/android/content/ContentResolver.html#openFileDescriptor(android.net.Uri, java.lang.String)`. To override this method, you must provide your own subclass of FileProvider.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | A content URI associated with a file, as returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html 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. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` | A new `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` with which you can access the file. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException.html` |   |

### query

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public @NonNull Cursor query(
    @NonNull Uri uri,
    @Nullable String[] projection,
    @Nullable String selection,
    @Nullable String[] selectionArgs,
    @Nullable String sortOrder
)
```

Use a content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)` to get information about a file managed by the FileProvider. FileProvider reports the column names defined in `https://developer.android.com/reference/android/provider/OpenableColumns.html`:

- `https://developer.android.com/reference/android/provider/OpenableColumns.html#DISPLAY_NAME`
- `https://developer.android.com/reference/android/provider/OpenableColumns.html#SIZE`

For more information, see `https://developer.android.com/reference/android/content/ContentProvider.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | A content URI returned by `https://developer.android.com/reference/androidx/core/content/FileProvider#getUriForFile(android.content.Context,java.lang.String,java.io.File)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] projection` | The list of columns to put into the `https://developer.android.com/reference/android/database/Cursor.html`. If null all columns are included. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html selection` | Selection criteria to apply. If null then all data that matches the content URI is returned. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] selectionArgs` | An array of `https://developer.android.com/reference/java/lang/String.html`, containing arguments to bind to the *selection* parameter. The *query* method scans *selection* from left to right and iterates through *selectionArgs* , replacing the current "?" character in *selection* with the value at the current position in *selectionArgs* . The values are bound to *selection* as `https://developer.android.com/reference/java/lang/String.html` values. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html sortOrder` | A `https://developer.android.com/reference/java/lang/String.html` containing the column name(s) on which to sort the resulting `https://developer.android.com/reference/android/database/Cursor.html`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/database/Cursor.html` | A `https://developer.android.com/reference/android/database/Cursor.html` containing the results of the query. |

### update

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public int update(
    @NonNull Uri uri,
    @NonNull ContentValues values,
    @Nullable String selection,
    @Nullable String[] selectionArgs
)
```

By default, this method throws an `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html`. You must subclass FileProvider if you want to provide different functionality.