Небольшой вопрос о менеджере загрузки в android. Это первый раз, когда я работаю с ним и успешно загрузил несколько файлов и открыл их. Но мой вопрос заключается в том, как проверить, завершена ли загрузка.
Ситуация заключается в том, что я загружаю PDF файл и открываю его, и обычно файл настолько мал, что он заканчивается перед открытием. Но если файл несколько больше, как я могу проверить, закончил ли диспетчер загрузки загрузку, прежде чем открывать ее.
Как я загружаю:
Intent intent = getIntent();
DownloadManager downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
Uri Download_Uri = Uri.parse(intent.getStringExtra("Document_href"));
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
//Restrict the types of networks over which this download may proceed.
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
//Set whether this download may proceed over a roaming connection.
request.setAllowedOverRoaming(false);
//Set the title of this download, to be displayed in notifications.
request.setTitle(intent.getStringExtra("Document_title"));
//Set the local destination for the downloaded file to a path within the application external files directory
request.setDestinationInExternalFilesDir(this,Environment.DIRECTORY_DOWNLOADS,intent.getStringExtra("Document_title") + ".pdf");
//Enqueue a new download and same the referenceId
Long downloadReference = downloadManager.enqueue(request);
Как открыть файл
Uri uri = Uri.parse("content://com.app.applicationname/" + "/Download/" + intent.getStringExtra("Document_title") + ".pdf");
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(uri, "application/pdf");
target.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(target);
Итак, где-то между загрузкой и открытием файла, я хочу, чтобы оператор if проверял, следует ли продолжать или ждать файл.