Question

in my application I would love to implement a progressDialog to the image download process and after this, i want call the intent ACTION_ATTACH_DATA. currently my code works fine but as you can see when it starts downloading, immediately called the intent. my goal is to show the intent after the download and with a progressdialog. Thanks for your help :)

code:

 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"));
Was it helpful?

Solution

DownloadManager works asynchronously. Your code will not wait for download to be completed. If you want to do something when file is downloaded, you need to listen to ACTION_DOWNLOAD_COMPLETE broadcast.

PS: you do not show Intent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top