我真的是Android上的新手,我正在尝试创建一个简单的应用程序,以从服务器下载视频文件...我在做研究,发现您可以使用downloadManager来使用它,它看起来很容易使用,但是看起来该选项仅接受url作为参数,并且为了下载视频,我必须发送(发布)一些参数以访问文件,我也正在阅读我们可以使用异步功能,但是我不确定是最好的方法。

谢谢!

我以这个网站为参考;
https://developer.android.com/reference/android/app/DownloadManager

最佳答案

你可以试试这个代码

DownloadManager.Request request = new DownloadManager.Request(Uri.parse("your_video_url"));
                                request.setDescription("download");
                                request.setTitle("your_file_name");

                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                    request.allowScanningByMediaScanner();
                                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                                }
                                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "your_file_name"+".mp4");
                                DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
                                manager.enqueue(request);

关于java - 如何从服务器下载视频文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56034750/

10-11 00:07