BackgroundDownloader无法将文件写入SD卡(WP8.1)

时间:2015-09-23 10:10:34

标签: download background windows-phone-8.1

抱歉我的英语不好...... 我的应用程序下载MP3文件并将其写入musicLibrary。下载通过BackgroundDownloader执行的文件。问题如下:内部手机内存中的下载完成没有问题,但SD卡上没有完成。 SD卡上的文件大小为0字节。 在清单中,应用程序具有对InternetClientServer,musicLibrary和removableStorage的许可。

public async void HandleSelectDownload(string urlDownload, string fileNameSave)
    {
        try
        {
            // Thông số tải nhạc
            var requestUri = new Uri(urlDownload, UriKind.RelativeOrAbsolute);

            downloadTo = await KnownFolders.MusicLibrary.CreateFileAsync(fileNameSave, CreationCollisionOption.GenerateUniqueName);
            BackgroundDownloader downloader = new BackgroundDownloader();
            DownloadOperation operation = downloader.CreateDownload(requestUri, downloadTo);

            //progressbar
            Progress<DownloadOperation> downloadProgress = new Progress<DownloadOperation>(DownloadProgress);
            // start download
            await operation.StartAsync().AsTask(downloadProgress);
            }

        }
        catch (Exception ex) { Debug.WriteLine("HandleSelectDownload Error : \n" + ex); }
    }

    public void DownloadProgress(DownloadOperation operation)
    {
        try
        {
            if (operation.Progress.TotalBytesToReceive == 0) return;

            int progress = (int)(100 * ((double)operation.Progress.BytesReceived / (double)operation.Progress.TotalBytesToReceive));

            Debug.WriteLine(String.Format("{0} of {1} kb. downloaded - %{2} complete.", operation.Progress.BytesReceived / 1024, operation.Progress.TotalBytesToReceive / 1024, progress));

            if (progress >= 100)
            {
                Debug.WriteLine("Finish!: {0} ", operation.ResultFile.Name);
            }
        }
        catch (Exception ex) { Debug.WriteLine("DownloadProgress Error :" + ex); }
    }

1 个答案:

答案 0 :(得分:0)

这是Windows 8 / 8.1中的一个已知问题,它一直是fixed in Windows 10。没有API更改。只需尝试在Windows 10设备中运行您的应用程序。