SecurityException with grantUriPermission when sharing a file with FileProvider

Well, after a week and a lot of trial and error, it seems the answer is to not specify permissions. So the App A Manifest should instead contain: <provider android:name=”android.support.v4.content.FileProvider” android:authorities=”au.com.example.AppA.fileprovider” android:exported=”false” android:grantUriPermissions=”true” > <meta-data android:name=”android.support.FILE_PROVIDER_PATHS” android:resource=”@xml/filepaths” /> </provider> ie, I removed the read and write permissions. My initial understanding, and failing to find documentation … Read more

FileProvider throws exception on GetUriForFile

I finally found good example code on how to create ContentProviders and FileProviders on https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider The actual error in my code was that in the Manifest file I had the provider tag outside of the application tag, but it must be inside. The Manifest must look like this: <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” android:versionCode=”1″ android:versionName=”1.0″ … Read more

How to get uri of captured photo?

Follow below steps. Step – 1 : Create provider_paths.xml in res/xml folder and write below code in it. <?xml version=”1.0″ encoding=”utf-8″?> <paths xmlns:android=”http://schemas.android.com/apk/res/android”> <external-path name=”external_files” path=”.” /> </paths> Step – 2 : Declare provider in manifest as below. <provider android:name=”android.support.v4.content.FileProvider” android:authorities=”${applicationId}.provider” android:exported=”false” android:grantUriPermissions=”true”> <meta-data android:name=”android.support.FILE_PROVIDER_PATHS” android:resource=”@xml/provider_paths” /> </provider> If you are facing error at: android:name=”android.support.v4.content.FileProvider” … Read more

Couldn’t find meta-data for provider with authority

First, write the following tag in manifest under the <application> tag <provider android:name=”androidx.core.content.FileProvider” android:authorities=”${applicationId}.provider” android:exported=”false” android:grantUriPermissions=”true”> <meta-data android:name=”android.support.FILE_PROVIDER_PATHS” android:resource=”@xml/provider_paths” /> </provider> Then create a xml folder in res and create a file named: provider_paths.xml and then copy paste the code: <?xml version=”1.0″ encoding=”utf-8″?> <paths xmlns:android=”http://schemas.android.com/apk/res/android”> <external-path name=”external_files” path=”.” /> </paths> And now here’s where most … Read more

Image share intent works for Gmail but crashes FB and twitter

Twitter (wrongly) assumes that there will be a MediaStore.MediaColumns.DATA column. Starting in KitKat the MediaStore returns null, so luckily, Twitter gracefully handles nulls, and does the right thing. public class FileProvider extends android.support.v4.content.FileProvider { @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor source = super.query(uri, projection, selection, selectionArgs, … Read more

Android install apk with Intent.VIEW_ACTION not working with File provider

After a lot of trying I have been able to solve this by creating different Intents for anything lower than Nougat as using the FileProvider to create an install intent with Android Versions before Nougat causes the error: ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSTALL_PACKAGE dat=content://XXX.apk flg=0x1 } While using a normal Uri … Read more

Android – file provider – permission denial

Turns out the only way to solve this is to grant permissions to all of the packages that might need it, like this: List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }

FileProvider – IllegalArgumentException: Failed to find configured root

Your file is stored under getExternalFilesDir(). That maps to <external-files-path>, not <files-path>. Also, your file path does not contain images/ in it, so the path attribute in your XML is invalid. Replace res/xml/file_paths.xml with: <?xml version=”1.0″ encoding=”utf-8″?> <paths> <external-files-path name=”my_images” path=”/” /> </paths> UPDATE 2020 MAR 13 Provider path for a specific path as followings: … Read more

How to use support FileProvider for sharing content to other apps?

Using FileProvider from support library you have to manually grant and revoke permissions(at runtime) for other apps to read specific Uri. Use Context.grantUriPermission and Context.revokeUriPermission methods. For example: //grant permision for app with package “packegeName”, eg. before starting other app via intent context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); //revoke permisions context.revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); As a … Read more