ProgressDialog DownloadManager

时间:2014-02-13 17:00:57

标签: android android-intent progressdialog download-manager

在我的应用程序中,我很乐意在图像下载过程中实现progressDialog,之后,我想调用意图ACTION_ATTACH_DATA。目前我的代码工作正常,但正如你可以看到它开始下载时,立即调用意图。我的目标是在下载后使用progressdialog显示意图。谢谢你的帮助:)

代码:

 Button impostacome = (Button)popupView2.findViewById(R.id.impostacome);
          impostacome.setOnClickListener(new Button.OnClickListener(){
       public void onClick(View v) {

         File folder = new File(Environment.getExternalStorageDirectory() + "/Wallpaper");
         boolean success = false;
         if (!folder.exists()) {
             success = folder.mkdirs();
         }
         if (!success) {
         } else {
         }          
    File direct = new File("/sdcard/Wallpaper/");

     if (!direct.exists()) {
         direct.mkdirs();
     }

     DownloadManager mgr = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

     Uri downloadUri = Uri.parse("http://www.brothersapp.com/immaginiapp/wallpaper/1");
     DownloadManager.Request request = new DownloadManager.Request(
             downloadUri);

     request.setAllowedNetworkTypes(
     DownloadManager.Request.NETWORK_WIFI
     | DownloadManager.Request.NETWORK_MOBILE)
     .setAllowedOverRoaming(false).setTitle("brothersapp download")
     .setDescription("The image is Downloading...")
     .setDestinationInExternalPublicDir("/brothersapp/", "/1.jpg/");
     mgr.enqueue(request);





     Intent myintent = new Intent(Intent.ACTION_ATTACH_DATA);
     Uri sendUri =  Uri.parse("file:///sdcard/brothersapp/1.jpg");    
     myintent.setDataAndType(sendUri, "image/*");
     startActivity(Intent.createChooser(myintent, "Set As"));

1 个答案:

答案 0 :(得分:0)

DownloadManager以异步方式工作。您的代码不会等待下载完成。如果您想在下载文件时执行某些操作,则需要收听ACTION_DOWNLOAD_COMPLETE广播。

PS:你没有显示意图。