如何使用确定按钮弹出下载完成

How to show download complete pop up with ok button

我在 Android Studio 中使用 webView 制作了应用程序,我的应用程序包含所有图像,因此我还在我的应用程序中实现了下载按钮,但是当有人点击下载按钮时,它只是下载图像,我想show pop when download is Finished ,像这样, 下载完成和下方的确定按钮

这是我的下载码

 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);

如何显示弹窗?

首先在build.gradle[=13中为MaterialDialog添加依赖=]

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));