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 8183099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:03:36+00:00 2026-06-07T01:03:36+00:00

I have a problem trying to get a .png image to my android phone.

  • 0

I have a problem trying to get a .png image to my android phone.
I am now this far:

URL url = new URL ("http://oranjelan.nl/oranjelan-bg.png");
  InputStream input = url.openStream();
  try { 
     String storagePath = Environment.getExternalStorageDirectory();
     OutputStream output = new FileOutputStream (storagePath + "/oranjelangbg.png");
     try {
    byte[] buffer = new byte[1000000];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
        output.write(buffer, 0, bytesRead);
        }
     } finally {
      output.close();
        }
    } finally {
   input.close();
 }

But I get the following error @ String storagePath = Environment.getExternalStorageDirectory(); The compiller says cannot convert file to string.

Then if i fool around a bit and try this piece of code:

URL url;

    void setup() {
    try {

        URL url = new URL ("http://oranjelan.nl/oranjelan-bg.png");
        InputStream input = url.openStream();{
        try {

            String storagePath = Environment.getExternalStorageDirectory().getName();
            OutputStream output = new FileOutputStream (storagePath + "/oranjelangbg.png");
                try {


byte[] buffer = new byte[1000000];
                    int bytesRead = 0;
                    while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
                    output.write(buffer, 0, bytesRead);
                    }
                    } finally {
            output.close();
            }
            } catch (IOException e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
    } finally {
        try {
            input.close();
            } catch (IOException e) {
            // TODO Auto-generated catch block
            throw new RuntimeException(e);
     }
   }    
 }    
    } catch (MalformedURLException ex) {
      throw new RuntimeException(ex);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      throw new RuntimeException(e);
    }
  }
}

then my android freezes when I launch the app.

Does anyone have any ideas?

  • 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-07T01:03:37+00:00Added an answer on June 7, 2026 at 1:03 am

    In addition to what Tanis.7x pointed out, you will need to move the network operations out of the UI thread and into something such as an AyncTask. Otherwise you will not be able to interact with the application until it finishes downloading – that may result in an application unresponsive message and a force close. In more recent android versions, doing networking on the main thread is an automatic exception, even if it does not result in delay.

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

Sidebar

Related Questions

I have a problem with this query trying to get a sum and a
Hey all, i have a problem with trying to get 2 forms to close
I'm trying to get a handle on whether we have a problem in our
I have a problem with a page where I am trying to get colorbox
I have a problem in firefox, where I'm trying to get a form submission
I'm trying to get a regexp to solve the next problem: I have some
I have what is likely a simple problem, whereby I am trying to get
I'm trying to get my head around solving the following problem. I have the
I have been trying to get thumbnails to work with an AsyncTask for image
I have a problem trying to turn my python code into an executable using

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.