FileProvider getUriForFile() error on Huawei devices

Update for Android N (leaving the original answer below and have confirmed this new approach works in production): As you noted in your update, many Huawei device models (e.g. KIW-L24, ALE-L21, ALE-L02, PLK-L01, and a variety of others) break the Android contract for calls to ContextCompat#getExternalFilesDirs(String).
 Rather than returning Context#getExternalFilesDir(String) (ie the default entry) as …

Read more

Implementing a File Picker in Android and copying the selected file to another location

STEP 1 – Use an Implicit Intent: To choose a file from the device, you should use an implicit Intent Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType(“*/*”); chooseFile = Intent.createChooser(chooseFile, “Choose a file”); startActivityForResult(chooseFile, PICKFILE_RESULT_CODE); STEP 2 – Get the absolute file path: To get the file path from a Uri, first, try using Uri uri …

Read more

Permission Denial while sharing file with FileProvider [duplicate]

Sorry about the late response. I solved it like this: Intent chooser = Intent.createChooser(intentShareFile, “Share File”); List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(chooser, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; this.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } startActivity(chooser); This helped me: Permission Denial with File Provider through intent

android.support.v4.content.FileProvider not found

As of AndroidX (the repackaged Android Support Library), the path is androidx.core.content.FileProvider so the updated provider tag would be: <provider android:name=”androidx.core.content.FileProvider” android:authorities=”${applicationId}.fileprovider” android:exported=”false” android:grantUriPermissions=”true”> <meta-data android:name=”android.support.FILE_PROVIDER_PATHS” android:resource=”@xml/file_paths” /> </provider> Android Support Libraries are now in the androidx.* package hierarchy. android.* is now reserved to the built-in Android System Libraries.

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); }

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

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

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