Cosimo Sguanci Cosimo Sguanci - 1 year ago 79
Android Question

Android intent doesn't work on .apk files

I'm developing a File Manager, and I open files this way:

fileName = fileToOpen.getName();
fileName = fileName.substring(fileName.lastIndexOf('.') + 1);
Intent intent = new Intent();
Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", fileToOpen);
intent.setDataAndType(uri, MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName));

This can handle almost all extension, but when I click on .apk files an ActivityNotFoundException gets thrown. I would like to launch the android installation screen.

Answer Source

Only on Android 7.0+ will the package installer know how to work with content Uri values. For earlier versions of Android, you have no choice but to have the APK on external storage somewhere and use a file Uri.

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