1

I succeeded in downloading a file from the server with download manager but I want to display a message if the download is completed how can I do this please help me.

DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setTitle("Franklyn Downloading " + "Sample" + ".mp3");
request.setDescription("Downloading " + "Sample" + ".mp3");
request.setVisibleInDownloadsUi(true);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/.Android/" +"/.Obs/"+"/.Android/"+"/.Android/"+"/.Android/"+"/.Android/"+ "/" + "Sample" + ".mp3");

refid = downloadManager.enqueue(request);

Log.e("OUT", "" + refid);

list.add(refid);
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114

2 Answers2

0

Broadcast intent action "ACTION_DOWNLOAD_COMPLETE" sent by the download manager when a download completes. So you need to register this receiver.

BroadcastReceiver downloadComplete = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        // show alert
    }
};

registerReceiver(downloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
0

Android DownloadManager send ACTION_DOWNLOAD_COMPLETE broadcast intent when a download completes.

IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(downloadReceiver, filter);

private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
    }
};

So you need to check your refId with broadcast receiver referenceId. If both matched then you need to show the alert dialog.

Chirag
  • 56,621
  • 29
  • 151
  • 198