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

  • Home
  • SEARCH
  • 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 4563354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:20:47+00:00 2026-05-21T18:20:47+00:00

I want to download an mp3 file using an AsyncTask or a thread. How

  • 0

I want to download an mp3 file using an AsyncTask or a thread.

How can I do this?

  • 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-05-21T18:20:47+00:00Added an answer on May 21, 2026 at 6:20 pm

    You can do something like this…

    When you decide to start downloading:

    new Thread(new Runnable()
      {
      @Override
      public void run()
           {
           File out;
           Downloader DDL;
           DDL=new Downloader();
           out=new File(Environment.getExternalStorageDirectory() + "/DestFileName.txt");
           DDL.DownloadFile("SourceURL",out);
    
           }
        }).start();
    

    Where the downloader class is

    public class Downloader {
    
    public void Downloader() 
            {
        // TODO Auto-generated method stub
        }
    
    public boolean DownloadFile(String url, File outputFile) 
        {
        try {
          URL u = new URL(url);
          URLConnection conn = u.openConnection();
          int contentLength = conn.getContentLength();
    
          DataInputStream stream = new DataInputStream(u.openStream());
    
          byte[] buffer = new byte[contentLength];
          stream.readFully(buffer);
          stream.close();
    
          DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
          fos.write(buffer);
          fos.flush();
          fos.close();
          } 
        catch(FileNotFoundException e) 
          {
          return false; 
          } 
        catch (IOException e) 
          {
          return false; 
          }
    
        return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to download an mp3 File from a Link on the Phone(Isolated Storage)
I want to download this picture using Ruby. How do I do that? http://farm1.static.flickr.com/92/218926700_ecedc5fef7_o.jpg
I want to allow only registered user's to download a .mp3 file. So, I
how can I force a download to start using curl? I want it to
can anybody give me links to dowlnload libmp3lame.so file.I want to convert mp3 stream
I am using AsyncTask to download different mp3's from webview. When I track my
I want to download a couple songs off of http://www.youtube-mp3.org/ . I'm using urllib2
I want to download a list of web pages. I know wget can do
I want to download .Net 4, but I can't find it. Where can I
I want to download a PDF file from a SQL Server database which is

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.