【问题标题】:How to show download complete pop up with ok button如何使用确定按钮显示下载完成弹出窗口
【发布时间】:2018-05-13 13:42:39
【问题描述】:

我在 Android Studio 中使用 webView 制作了应用程序,我的应用程序包含所有图像,所以我还在我的应用程序中实现了下载按钮,但是当有人点击下载按钮时它只是下载图像,我想在下载时显示弹出窗口完成了,像这样的, 下载完成并在确定按钮下方

这是我的下载代码

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

如何显示弹出窗口?

【问题讨论】:

    标签: android android-studio download download-manager


    【解决方案1】:

    首先,在build.gradle

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

    【讨论】:

    • 谢谢先生,它有效:XD 现在我可以在点击确定后显示插页式广告吗?
    猜你喜欢
    • 1970-01-01
    • 2012-07-21
    • 2013-03-11
    • 2020-09-12
    • 2012-08-10
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多