简体   繁体   中英

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();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", fileToOpen);
intent.setDataAndType(uri, MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM