When I try to install an APK using:
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setData(Uri.fromFile(true_path));
startActivity(installIntent);
I receive the error:
file:///...app-debug.apk exposed beyond app through Intent.getData()
I believe that intents cannot use file:// URIs; how do I build an APK using Android Studio, such that it can be used by an intent?
The correct way to do it is
File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
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.