-1

Обычные файлы грузятся. Но, когда имя файла имеет название, например, "Иванов И.И..jpg" - приложение рушится. Предполагаю, что это из-за 2 точек в названии файла перед расширением. Проблема:

Или тут: DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); или тут: request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Ivanov I.I..jpg"); DownloadManager - стандарт. Есть варианты решения?

String url = "https://myserver.com/Ivanov I.I..jpg";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Ivanov I.I..jpg downloading");
request.setTitle("Some title");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Ivanov I.I..jpg");

// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);

Normal files are loaded. But when the filename has a name, for example, "Ivanov I.I..jpg" - the application crashes. I assume that this is due to 2 dots in the file name before the extension. Are there solutions?

3
  • Приведите текст ошибки и на какую строку она указывает 9 фев 2022 в 17:59
  • Предположим на 2 проблему. Парсить имя файла и пытаться переписать название сохраняемого файла?
    – webpauk
    9 фев 2022 в 19:26
  • Пока вы не приведете текст ошибки и строки, где она возникла, ничем вам помочь не получится 10 фев 2022 в 13:58

1 ответ 1

0

Проблема была таки тут:

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Ivanov I.I..jpg");

Поменял 2 точки и проблема исчезла

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Ivanov I.I.jpg");

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.