[英]Build, Install APK using Intent
当我尝试使用以下方法安装APK时:
val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setData(Uri.fromFile(true_path));
startActivity(installIntent);
我收到错误:
file:///...app-debug.apk exposed beyond app through Intent.getData()
我相信意图不能使用file:// URI; 如何使用Android Studio构建APK,以使其可以被意图使用?
正确的方法是
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.