繁体   English   中英

无法以编程方式安装apk文件

[英]Failed to install an apk file programmatically

我以编程方式从Google云端硬盘下载了apk文件。 每次我尝试以编程方式安装它时,都只会显示诸如“尚未安装应用程序”之类的字样(我已将其翻译)。 我比较了原始文件和下载文件的校验和,以查看下载文件是否损坏,但不是。

Logcat不打印有关此的任何信息。 这是我尝试安装的方式:

    @Override
    public void onUpdateDownloaded(String path) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

解决了问题:我只是尝试安装一个较低版本的应用程序,这导致了问题。

它可能不适用于Uri.fromFile(new File(path))

首先以编程方式将apk文件复制到sd卡,然后

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() 
+ "/yourApplication.apk")), "application/vnd.android.package-archive");
startActivity(intent);

暂无
暂无

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

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