Как показать загрузку завершенной, всплывающее окно с кнопкой ОК - PullRequest
0 голосов
/ 13 мая 2018

я сделал приложение с webView в Android Studio, мое приложение содержит все изображения, поэтому я также добавил кнопку загрузки в свое приложение, но когда кто-то нажимает на кнопку загрузки, это просто загружает изображение, я хочу, чтобы всплывающее окно появлялось, когда загрузкаЗакончено, что-то вроде этого, Загрузка завершена и ниже кнопка ОК

это мой код загрузки

 Uri source = Uri.parse(url);
                // Make a new request pointing to the .apk url
                DownloadManager.Request request = new DownloadManager.Request(source);
                // appears the same in Notification bar while downloading
                request.setDescription("Description for the DownloadManager Bar");
                request.setTitle("PunjabiDharti.jpg");
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                }
                // save the file in the "Downloads" folder of SDCARD
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "PunjabiDharti.jpg");
                // get download service and enqueue file
                DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
                manager.enqueue(request);

как показать всплывающее окно?

1 Ответ

0 голосов
/ 13 мая 2018

Сначала добавьте зависимости для MaterialDialog in build.gradle

dependencies {
    // ... other dependencies here
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
}

Создайте Обработчик BroadcastReceiver

BroadcastReceiver downloadListener = new BroadcastReceiver(){
    public void onReceive(Context ct, Intent intent){
        new MaterialDialog.Builder(this)
              .title("Download Completed")
              .content("Download Successfully Completed")
              .positiveText("OK")
              .show();
    }
};

А теперь Регистрация получателя

registerReceiver(downloadListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
...