简体   繁体   English

使用Intent构建,安装APK

[英]Build, Install APK using Intent

When I try to install an APK using: 当我尝试使用以下方法安装APK时:

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; 我相信意图不能使用file:// URI; how do I build an APK using Android Studio, such that it can be used by an intent? 如何使用Android Studio构建APK,以使其可以被意图使用?

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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