Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android StorageAccessFramework和DownloadManager存在问题_Android_Uri_Saf - Fatal编程技术网

Android StorageAccessFramework和DownloadManager存在问题

Android StorageAccessFramework和DownloadManager存在问题,android,uri,saf,Android,Uri,Saf,我有一个问题。我正在开发一些流媒体/视频下载应用程序。 我正在使用的视频下载 请求是提供用户选择保存目的地的信息(SD卡或内部电话存储) 我和下载经理在棒棒糖上有问题 我建议用户选择存储我下载的文件的目录: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_FOR_DESTINATION); 在onActivityResult中,我通

我有一个问题。我正在开发一些流媒体/视频下载应用程序。 我正在使用的视频下载

请求是提供用户选择保存目的地的信息(SD卡或内部电话存储)

我和下载经理在棒棒糖上有问题

我建议用户选择存储我下载的文件的目录:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, REQUEST_CODE_FOR_DESTINATION);
在onActivityResult中,我通过

Uri treeUri = data.getData();
DocumentFile destinationDirUri = DocumentFile.fromTreeUri(this, treeUri);
现在,我需要将此目的地设置为DownloadManager.Request的目的地

Request request = new DownloadManager.Request(Uri.parse(getDownloadUrl()));
request.setTitle(downloadInfo.getTitle());
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationUri(destinationDirUri);
在我选择“下载/视频”目录后,执行

DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
我越来越

E/RecordDownloader﹕ Error while retrieving download infos    
W/System.err﹕ java.lang.IllegalArgumentException: Not a file URI: content://com.android.externalstorage.documents/tree/primary%3ADownload%2Fvideo
W/System.err﹕ at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
W/System.err﹕ at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
W/System.err﹕ at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
W/System.err﹕ at android.content.ContentResolver.insert(ContentResolver.java:1207)
W/System.err﹕ at android.app.DownloadManager.enqueue(DownloadManager.java:946)
W/System.err﹕ at ch.teleboy.download.RecordDownloader.enqueueDownloadRequest(RecordDownloader.java:102)
W/System.err﹕ at ch.teleboy.download.RecordDownloader.access$300(RecordDownloader.java:48)
W/System.err﹕ at ch.teleboy.download.RecordDownloader$DownloaderTask.run(RecordDownloader.java:191)
W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
如果我尝试将一些文件写入所选位置,它会起作用

DocumentFile newFile = destinationDirUri.createFile("text/plain", "test.txt");
OutputStream out = getContentResolver().openOutputStream(newFile.getUri());
out.write("Some dummy text...".getBytes());
out.close()

有什么建议吗

你能解决这个问题吗?如果是,请描述解决方案。不,我没有。我们为了更快乐的时间而推迟了功能:)你是否在结果上从活动中拯救了treeURI?因为我认为它已经被解析了,而你正试图再次解析它,这可能会导致问题,这只是一个猜测……这是很久以前的事了,但我认为情况就是这样。这是有道理的。如果我有时间的话,我会找到那根树枝试一下。也许我们可以帮助别人。谢谢,有人找到解决办法了吗?