Android can't open file

隐身守侯 提交于 2019-12-22 17:14:32

问题


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

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

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

What am I doing wrong?


回答1:


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



来源:https://stackoverflow.com/questions/27404478/android-cant-open-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!