gpt4 book ai didi

android - 以编程方式从 SD 卡安装应用程序

转载 作者:行者123 更新时间:2023-11-30 01:53:55 24 4
gpt4 key购买 nike

我正在使用此代码从 SD 卡安装应用

Toast.makeText(this, "running", Toast.LENGTH_LONG).show();
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file:///sdcard/app.apk"),
"application/vnd.android.package-archive");
startActivity(promptInstall);

我怎么会收到解析错误:解析包时出现问题

我已经在 list 文件中给出了权限

 <uses-permission android:name="android.permission.INSTALL_PACKAGES" />

我已经把apk放到sdcard里了

ps:应用程序正在通过文件管理器安装

最佳答案

您可以更改指定 URI 的方式。试试这个;

Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+File.separator+"<DIRECTORY_NAME>"+File.separator+"<YOUR_APK_FILE.apk>")),
"application/vnd.android.package-archive");
startActivity(promptInstall);

关于android - 以编程方式从 SD 卡安装应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32562135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com