我正在开发必须从服务器下载视频的应用程序。我正在使用下载管理器,因为它将处理所有后端方案。我面临的问题是我的关注文件夹中没有下载视频。我已经使用File创建了一个文件夹。任何想法我将如何获得它?
private void downloadVideos(String[] videosName, String moduleName) {
File folder = new File(Environment.getExternalStorageDirectory() + File.separator + DatabaseHelper.PROJECT_NAME);
boolean success = true;
if (!folder.exists())
success = folder.mkdirs();
if (!success) return;
folder = new File(folder.getPath() + File.separator + moduleName);
if (!folder.exists())
success = folder.mkdirs();
if (!success) return;
for (int i = 0; i < videosName.length; i++) {
String fileName = videosName[i];
File file = new File(folder.getPath(), fileName);
if (file.exists()) {
Toast.makeText(getContext(), "file already exists", Toast.LENGTH_SHORT).show();
} else {
NetworkInfo networkInfo = ((ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(CONSTANTS.Video_URL + fileName + ".mp4");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalPublicDir(file.getPath(), fileName)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setTitle("Downloading " + fileName);
refID = downloadManager.enqueue(request);
} else {
Toast.makeText(getContext(), "Internet connectivity issue", Toast.LENGTH_SHORT).show();
}
}
}
getActivity().registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}