简体   繁体   English

下载管理器无法在LG G设备上下载文件

[英]download manager failed to download a file on lg g devices

When i'm trying to run the following code on my nexus 5 it shows a progress bar and actually download the file. 当我尝试在nexus 5上运行以下代码时,它显示进度条并实际下载文件。

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
                    request.setDescription("");
                    request.setTitle("");
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        request.allowScanningByMediaScanner();
                        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                    }


                    DownloadManager manager = (DownloadManager) getSystemService(Environment.DIRECTORY_MUSIC);
                    manager.enqueue(request);
                }

but when i try the same thing on a lg g2 or lg g3 the file doesn't even start download and i get this message right after the beginning. 但是当我在lg g2或lg g3上尝试相同的操作时,该文件甚至都没有开始下载,并且我在开始后立即收到此消息。 关于lg devides

I think the problem is that lg phones have a different music dir and Environment.DIRECTORY_MUSIC gives me an empty dir. 我认为问题在于lg手机具有不同的音乐目录,而Environment.DIRECTORY_MUSIC给我一个空的目录。 If that is the problem does anyone know a way to get a correct dir for all devices? 如果这是问题所在,那么有人知道为所有设备获取正确目录的方法吗? and if not does anyone have a clue what is the problem and how do i get it fixed? 如果没有,那么没人知道这是什么问题,如何解决?

It looks like you are passing a bad name into the getSystemService() call: 似乎您正在将一个坏名传递给getSystemService()调用:

(DownloadManager) getSystemService( Environment.DIRECTORY_MUSIC );

Should be something like: 应该是这样的:

(DownloadManager) getSystemService( DOWNLOAD_SERVICE );

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

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