0

i made app with webView in Android Studio , my app contains all images so i have also implemented download button in my app , but when someone click on download button it just download the image , i want to show pop up when download is Finished , something like this, Download Completed and below Ok button

this is my code of download

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

how to show pop up ?

Chand Ninder
  • 161
  • 5
  • 19

1 Answers1

1

First, add Dependencies for MaterialDialog in build.gradle

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

Create a BroadcastReceiver Handler

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

And now register Receiver

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