Это файл для скачивания Код
`String msg = attach.getName ();
byte [] b = msg.getBytes (StandardCharsets.UTF_8);
Строка v = новая строка (b, StandardCharsets.UTF_8);
String fileUrl = attach.getFilePath() + "/" + attach.getName();
String fileName = attach.getName();
File file = new File(Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + attach.getName());
if (file.exists()) {
openFile(fileName);
} else {
if (ActivityCompat.checkSelfPermission(context,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(
context,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// FILE permission has not been granted.
requestFilePermission();
} else {
// FILE permissions is already available, show the FILE download.
Log.i(TAG, "FILE permission has already been granted. Downloading FILE.");
fileUrl = Utils.getUrl(context.getApplicationContext()) + fileUrl;
fileUrl = fileUrl.replaceAll(" ", "%20");
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileUrl));
request.setDescription(vattach.getName());
request.setTitle(attach.getName());
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, v);
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
assert manager != null;
manager.enqueue(request);
}
`