Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:27:51+00:00 2026-06-09T23:27:51+00:00

How do you implement Progress Download Dialog based on the codes below? My codes

  • 0

How do you implement Progress Download Dialog based on the codes below? My codes downloads images from a specific URL then it saves the image file into SD Card and set the image as wallpaper. I want to show a Progress Download Dialog when the user touches the options menu button setwallpaper().

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.set_wallpaper:
                SetWallpaper(image_url);
                return true;
            default:
                return false;
        }
    }



public void SetWallpaper(String image_url)
        {   
        URL myFileUrl = null;
            try
        {   
                myFileUrl = new URL(image_url); 
        }
            catch (MalformedURLException e)
            {      
                e.printStackTrace();  
            }   
            Bitmap bmImg = null;
            try {  
                HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();   
                conn.setDoInput(true);   
                conn.connect();     
                //int length = conn.getContentLength(); 
            InputStream is = conn.getInputStream();
            bmImg = BitmapFactory.decodeStream(is); 
            }
                catch (IOException e)
                {       
                    e.printStackTrace();  
                }   
        try {       

            String path = myFileUrl.getPath();
            String idStr = path.substring(path.lastIndexOf('/') + 1);
            File filepath = Environment.getExternalStorageDirectory();
            File dir = new File (filepath.getAbsolutePath() + "/Wallpaper/");
                dir.mkdirs();
                String fileName = idStr;
                File file = new File(dir, fileName);
                FileOutputStream fos = new FileOutputStream(file);

                bmImg.compress(CompressFormat.JPEG, 75, fos);   
                fos.flush();    
                fos.close();       

                WallpaperManager wpm = WallpaperManager.getInstance(getBaseContext());
                wpm.setBitmap(bmImg);

        }
        catch (Exception e){


            e.printStackTrace();  
        }
        }

My attempt : Caught Exception . Please refer below codes

    public class SingleMenuItemActivity  extends Activity {

    // XML node keys
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "artist";  
static final String KEY_THUMB_URL = "thumb_url";
ProgressBar progressbar;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);

        ImageView image = (ImageView) findViewById(R.id.single_image);
        Intent in = getIntent();

        String image_url = in.getStringExtra(KEY_THUMB_URL);


        ImageLoader imgLoader = new ImageLoader(getApplicationContext());


        imgLoader.DisplayImage(image_url, image);

        String title = in.getStringExtra(KEY_TITLE);
        String artist = in.getStringExtra(KEY_ARTIST);


        TextView lblName = (TextView) findViewById(R.id.name_title);
        TextView lblCost = (TextView) findViewById(R.id.name_artist);
        progressbar = (ProgressBar) findViewById(R.id.loadingBar);

        lblName.setText(title);
        lblCost.setText(artist);


    }

    public class loadImageTask extends AsyncTask<String, Void, Void>
    {
        //Drawable imgLoad;
        URL myFileUrl = null;
        Bitmap bmImg = null;
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            Intent in = getIntent();
        String image_url = in.getStringExtra(KEY_THUMB_URL);
        try {
            myFileUrl = new URL(image_url);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        super.onPreExecute();

        progressbar.setVisibility(View.VISIBLE);
    }

        @Override
        protected Void doInBackground(String... params) {
            // TODO Auto-generated method stub

            try {  
                HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();   
                conn.setDoInput(true);   
                conn.connect();     
                InputStream is = conn.getInputStream();
                bmImg = BitmapFactory.decodeStream(is); 
            }
            catch (IOException e)
            {       
                e.printStackTrace();  
            }
            try {       

                String path = myFileUrl.getPath();
                String idStr = path.substring(path.lastIndexOf('/') + 1);
            File filepath = Environment.getExternalStorageDirectory();
            File dir = new File (filepath.getAbsolutePath() + "/Wallpaper/");
                dir.mkdirs();
                String fileName = idStr;
                File file = new File(dir, fileName);
                FileOutputStream fos = new FileOutputStream(file);
                bmImg.compress(CompressFormat.JPEG, 75, fos);   
                fos.flush();    
                fos.close();       
            }
            catch (Exception e)
                    {
                        e.printStackTrace();  
                    }
            return null;   
        }
        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);

            if(progressbar.isShown())
            {
                progressbar.setVisibility(View.GONE);

            }
        }
    }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent in = getIntent();
        String image_url = in.getStringExtra(KEY_THUMB_URL);
        switch (item.getItemId()) {
            case R.id.save_image:
                new loadImageTask().execute(image_url);

                return true;
            default:
                return false;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:27:52+00:00Added an answer on June 9, 2026 at 11:27 pm

    Here you can use the AsyncTask for the show the progressbar/dialogbox .

    Show the progress bar visible inside the onPreExecute() method. And performs the image loading operations inside the doInBackground() method. Once this operation is done, we will make progress bar invisible and make imageview visible with that loaded image inside the onPostExecute() method.

    For more information check this LINK

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using AsyncTask to download files. There i implemented progress: //Updating progress dialog
I my application i am going to implement the Progress dialog till its getting
I want to implement an progress bar in my C++ windows application when downloading
I want to implement a progress bar showing elapsed seconds in bash. For this,
I am creating an application and I would like to implement a progress window
Already finished implementing the player. I want to implement the progress bar. But I
I'm trying to implement a upload progress bar the HTML5 way, by using the
I am trying to implement the SVProgressHUD progress activity indicator. I copied the class
What is the best way to implement some kind of progress indicator in Play?
I'm trying to implement the progress notification mechanism when copying files. I'm doing this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.