[英]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.