diff --git a/README.md b/README.md index fb8fce9..494fb49 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,44 @@ One use case is a custom ringtone in a notification. Check out the blog post [No ## Usage -It's configured just like [FileProvider](https://developer.android.com/reference/android/support/v4/content/FileProvider.html). +Add a provider element to your Manifest: +```xml + + ... + + ... + + + + + + ... + + +``` + +Create a file `res/xml/publicfileprovider_paths.xml` with the configuration, e.g. + +```xml + + + +``` +The format of this file is identical to that of [FileProvider](https://developer.android.com/reference/android/support/v4/content/FileProvider.html). + +To get the `content://` URI for a file you want to expose to all apps on the device use the following code: + +```java +File notificationSoundsPath = new File(Context.getFilesDir(), "notification_sounds"); +File myNotificationSoundFile = new File(imagePath, "ding.ogg"); +Uri contentUri = getUriForFile(getContext(), "com.mydomain.publicfileprovider", myNotificationSoundFile); +``` ## License diff --git a/library/src/main/java/de/cketti/fileprovider/PublicFileProvider.java b/library/src/main/java/de/cketti/fileprovider/PublicFileProvider.java index 1f46fd3..1c4b324 100644 --- a/library/src/main/java/de/cketti/fileprovider/PublicFileProvider.java +++ b/library/src/main/java/de/cketti/fileprovider/PublicFileProvider.java @@ -80,7 +80,7 @@ * de.cketti.fileprovider.PublicFileProvider. 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 + * com.mydomain.publicfileprovider. Set the android:exported attribute to * true. For example: *
  *<manifest>
@@ -89,7 +89,7 @@
  *        ...
  *        <provider
  *            android:name="de.cketti.fileprovider.PublicFileProvider"
- *            android:authorities="com.mydomain.fileprovider"
+ *            android:authorities="com.mydomain.publicfileprovider"
  *            android:exported="true">
  *            ...
  *        </provider>
@@ -108,7 +108,7 @@
  * 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/"/>
+ *    <files-path name="my_notification_sounds" path="notification_sounds/"/>
  *    ...
  *</paths>
  *
@@ -201,22 +201,22 @@ *
*

* 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. + * For example, you can add them to a new file called res/xml/publicfileprovider_paths.xml. * To link this file to the PublicFileProvider, add a * <meta-data> element * as a child of the <provider> element that defines the PublicFileProvider. Set the * <meta-data> element's "android:name" attribute to * de.cketti.fileprovider.PUBLIC_FILE_PROVIDER_PATHS. Set the element's "android:resource" attribute - * to @xml/file_paths (notice that you don't specify the .xml + * to @xml/publicfileprovider_paths (notice that you don't specify the .xml * extension). For example: *

  *<provider
  *    android:name="de.cketti.fileprovider.PublicFileProvider"
- *    android:authorities="com.mydomain.fileprovider"
+ *    android:authorities="com.mydomain.publicfileprovider"
  *    android:exported="true">
  *    <meta-data
  *        android:name="de.cketti.fileprovider.PUBLIC_FILE_PROVIDER_PATHS"
- *        android:resource="@xml/file_paths" />
+ *        android:resource="@xml/publicfileprovider_paths" />
  *</provider>
  *
*

Generating the Content URI for a File

@@ -231,17 +231,17 @@ * ContentResolver.openFileDescriptor} to get a {@link ParcelFileDescriptor}. *

* For example, suppose your app is offering files to other apps with a PublicFileProvider that has the - * authority com.mydomain.fileprovider. To get a content URI for the file + * authority com.mydomain.publicfileprovider. 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(), "images");
  *File newFile = new File(imagePath, "default_image.jpg");
- *Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
+ *Uri contentUri = getUriForFile(getContext(), "com.mydomain.publicfileprovider", newFile);
  *
* As a result of the previous snippet, * {@link #getUriForFile(Context, String, File) getUriForFile()} returns the content URI - * content://com.mydomain.fileprovider/my_images/default_image.jpg. + * content://com.mydomain.publicfileprovider/my_images/default_image.jpg. */ public class PublicFileProvider extends ContentProvider { private static final String[] COLUMNS = { OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };