简体   繁体   English

Android无法打开文件

[英]Android can't open file

I'm trying to download an apk file from server via DownloadManager: 我正在尝试通过DownloadManager从服务器下载apk文件:

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

When the apk is downloaded and I press it I'm getting "can't open file message", 下载apk并按下它时,我收到“无法打开文件消息”,
But if I download that apk via Browser instead of DownloadManger : 但是,如果我通过浏览器而不是DownloadManger下载该apk:

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

The apk works fine. APK工作正常。
The device is open for "Unknown sources" and it's version is 4.1.2 该设备对“未知来源”开放,其版本为4.1.2

What am I doing wrong? 我究竟做错了什么?

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

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

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