Cosimo Sguanci Cosimo Sguanci - 5 months ago 27
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.


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.