After downloading the apk file, I need to find it in the Donwloads folder, run and install it, it all works up to Android 11, but now there is a problem. I think this is due to a change in file access, but strangely, it works if there are no files, and the download is the first, but if there is already a file there (for example test.apk), it downloads the second apk, call it test-1.apk and does not see them anymore.
In older versions, I got files like this:
//set file
request.setDestinationInExternalPublicDir(DIRECTORY_DOWNLOADS, APK_NAME);
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
//get file
final String path = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) + "/" + APK_NAME;
final FilenameFilter filenameFilter = (file, s) -> APK_NAME.equals(s);
final File[] files = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).listFiles(filenameFilter);
and used the "files" array but getExternalStoragePublicDirectory is now deprecated and one should use something like there https://stackoverflow.com/a/57649669/6040706 But I don't understand how I can use this, can anyone help?