private void StartDownload()
{
string fileUrl = "http://www.xxx.com/doc/2.doc";
DownloadManager m_DownloadManager = (DownloadManager)GetSystemService( Context.DownloadService);
DownloadManager.Request request = new DownloadManager.Request(Android.Net.Uri.Parse(fileUrl));
request.SetDestinationUri(Android.Net.Uri.Parse("file://" + GetMyAppDir() + "/2.doc")); //添加"file://"前缀解决此问题
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
long requestId = m_DownloadManager.Enqueue(request);
}
public string GetMyAppDir()
{
var path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads);
var dir = path.AbsolutePath + Java.IO.File.Separator + "MyAppFolder";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
return dir;
}