安卓无法打开文件 [英] Android can't open file

查看:81
本文介绍了安卓无法打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 DownloadManager 从服务器下载 apk 文件:

I'm trying to download an apk file from server via DownloadManager:

dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        request.setMimeType("application/vnd.android.package-archive");
        request.allowScanningByMediaScanner();
        enqueue = dm.enqueue(request);

下载apk并按下它时,我收到无法打开文件消息",
但是,如果我通过浏览器而不是 DownloadManger 下载该 apk:

When the apk is downloaded and I press it I'm getting "can't open file message",
But if I download that apk via Browser instead of DownloadManger:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

apk 工作正常.
该设备已针对未知来源"开放,其版本为 4.1.2

The apk works fine.
The device is open for "Unknown sources" and it's version is 4.1.2

我做错了什么?

推荐答案

尝试将 apk 文件保存到本地存储,然后使用直接文件 URI 打开它

try saving the apk file to your local storage and then opening it using a direct file URI

这篇关于安卓无法打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆