Я пишу простой фрагмент для загрузки файла с локального сервера.
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
String filePath= null;
filePath = getApplicationContext().getFilesDir().getAbsolutePath();
filePath = this.getFilesDir().getAbsolutePath();
HERE-----**//request.setDescription("Downloading GeoJSON").setTitle("filename");**
//request.setDestinationUri(Uri.parse(filePath));
request.setDestinationInExternalPublicDir("Folder", "files");
request.setVisibleInDownloadsUi(true);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setMimeType("application/octet-stream");
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
downloadReference = downloadManager.enqueue(request);
Я хочу установить имя файла в заголовке, а также хочу сохранить файл с тем же именем.
Я знаю, что мы можем извлечь имя файла в BroadcastReceiver
, но эта трансляция будет получена только после завершения загрузки.
Ниже приведен код веб-службы —
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/geojson2")
public Response getFile() {
File file = new File(GEOJSON_FILE_PATH);
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.header("Content-Disposition", "attachment; filename=" + file.getName()) //optional
.header("Content-Length", file.length()+"")
.build();
}
URL-адрес веб-службы выглядит следующим образом: http://localhost:8080/NFZ_WS/rest/hello/geojson
Итак, мой вопрос заключается в том, как получить имя файла при постановке в очередь URI. Скажите, пожалуйста, нужно ли мне редактировать веб-сервис.
http://localhost:8080/NFZ_WS/rest/hello/geojson
. Я не получаю имя файла из URL. - person Anas Azeem   schedule 11.05.2015