如何使用Android下载管理器添加进度?

时间:2018-06-12 03:33:22

标签: java android

我正在使用下载管理器从服务器下载文件 以及如何在下载管理器中添加进度下载?

 DownloadPdf = (Button) findViewById(R.id.downloadpdf);
    DownloadPdf.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

           File file = new File (Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS)+"/Pdf/" + "/" + name + ".pdf");
            if (file.exists()) {
                Toast.makeText(CatalogDetailActivity.this, "File Sudah ada", Toast.LENGTH_SHORT).show();
            } else {

          Download_Uri = Uri.parse(testing);
            DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
            request.setAllowedOverRoaming(false);
            // request.setTitle("Downloading");
            request.allowScanningByMediaScanner();
            //request.setDescription("Downloading");
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
            request.setVisibleInDownloadsUi(false);
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/Pdf/" + "/" + name + ".pdf");
            refid = downloadManager.enqueue(request);
           }
        }
    });
}

0 个答案:

没有答案
相关问题