Mahsa Mahsa -4 years ago 103
Android Question

Android share app's apk using FileProvider

I've tried to share the app's apk file through intent.The provider in my manifest file:

android:authorities="package name"
android:resource="@xml/mypaths" />

and the mypaths file is:

<external-path name="apk_folder"/>

I set intent and the File path as below:

String packageName = getContext().getPackageName();
PackageManager pm = getContext().getPackageManager();
String apk = null;
try {
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
apk = ai.publicSourceDir;

} catch (PackageManager.NameNotFoundException e) {
File apkFile = new File(apk);

Uri uri = FileProvider.getUriForFile(getContext(), "package name", apkFile);

Intent intent = ShareCompat.IntentBuilder.from(getActivity())
.setChooserTitle("Share via")


I get IllegalArgumentException :

Failed to find configured root that contains /data/app/package

Please help me to find out my mistakes.

Answer Source

There is no available root in FileProvider that will handle your designated location. You would need to create your own ContentProvider for this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download