{"id":17960282,"url":"https://github.com/cketti/publicfileprovider","last_synced_at":"2025-03-25T03:31:21.478Z","repository":{"id":57730328,"uuid":"68367220","full_name":"cketti/PublicFileProvider","owner":"cketti","description":"Android library to publicly expose files via content:// URI. Consider using FileProvider instead!","archived":false,"fork":false,"pushed_at":"2017-04-04T00:10:39.000Z","size":179,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T08:37:08.232Z","etag":null,"topics":["android","fileprovider","library","notifications"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cketti.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-16T09:19:11.000Z","updated_at":"2024-08-17T10:14:13.000Z","dependencies_parsed_at":"2022-09-26T16:40:35.646Z","dependency_job_id":null,"html_url":"https://github.com/cketti/PublicFileProvider","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cketti%2FPublicFileProvider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cketti%2FPublicFileProvider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cketti%2FPublicFileProvider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cketti%2FPublicFileProvider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cketti","download_url":"https://codeload.github.com/cketti/PublicFileProvider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394732,"owners_count":20608122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","fileprovider","library","notifications"],"created_at":"2024-10-29T11:05:58.827Z","updated_at":"2025-03-25T03:31:21.466Z","avatar_url":"https://github.com/cketti.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PublicFileProvider\n\nPublicFileProvider is a special subclass of [`ContentProvider`](https://developer.android.com/reference/android/content/ContentProvider.html) that facilitates exposing files associated with an app by creating a `content://` URI for a file instead of a `file:///` URI.\n\n**WARNING:** Most of the time this is NOT what you want. Use [FileProvider](https://developer.android.com/reference/android/support/v4/content/FileProvider.html) to only grant temporary access to files, e.g. when [sharing](https://developer.android.com/training/secure-file-sharing/index.html) content to other apps.\n \nPublicFileProvider is a modified version of FileProvider with the specific goal to expose files without using Android's URI permission mechanism. This can come in handy when you have to provide a `content://` URI but can't easily grant read access to whatever app ends up accessing the content.\nOne use case is a custom ringtone in a notification. Check out the blog post [Notifications, Sounds, Android 7.0, and Aggravation](https://commonsware.com/blog/2016/09/07/notifications-sounds-android-7p0-aggravation.html) for more details.\nI also wrote a bit about how this library came to be: [When URI permissions are in the way](http://cketti.de/2017/04/03/when-uri-permissions-are-in-the-way/)\n\n\n## Usage\n\nAdd a provider element to your Manifest:\n\n```xml\n\u003cmanifest\u003e\n    ...\n    \u003capplication\u003e\n        ...\n        \u003cprovider\n            android:name=\"de.cketti.fileprovider.PublicFileProvider\"\n            android:authorities=\"com.mydomain.publicfileprovider\"\n            android:exported=\"true\"\u003e\n            \n            \u003cmeta-data\n                android:name=\"de.cketti.fileprovider.PUBLIC_FILE_PROVIDER_PATHS\"\n                android:resource=\"@xml/publicfileprovider_paths\" /\u003e\n        \n        \u003c/provider\u003e\n        ...\n    \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nCreate a file `res/xml/publicfileprovider_paths.xml` with the configuration, e.g.\n\n```xml\n\u003cpaths xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n    \u003cfiles-path name=\"my_notification_sounds\" path=\"notification_sounds/\"/\u003e\n\u003c/paths\u003e\n```\nThe format of this file is identical to that of [FileProvider](https://developer.android.com/reference/android/support/v4/content/FileProvider.html).\n\nTo get the `content://` URI for a file you want to expose to all apps on the device use the following code:\n\n```java\nFile notificationSoundsPath = new File(Context.getFilesDir(), \"notification_sounds\");\nFile myNotificationSoundFile = new File(imagePath, \"ding.ogg\");\nUri contentUri = getUriForFile(getContext(), \"com.mydomain.publicfileprovider\", myNotificationSoundFile);\n```\n\n\n## Include the library\n\nThe library is available on Maven Central. Add this to your `dependencies` block in `build.gradle`:\n\n```groovy\ncompile 'de.cketti.fileprovider:public-fileprovider:1.0.0'\n```\n\n\n## License\n\n    Copyright 2016 cketti\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcketti%2Fpublicfileprovider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcketti%2Fpublicfileprovider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcketti%2Fpublicfileprovider/lists"}