0

i'm a new Android developer and I'm developing an application that display image from an url adress. It works fine in wifi but doesn't work in 3g. Here's the code :

private void downloadImage(String urlPar, boolean imageSuivant) {

        try {
            URL urlImage = new URL(urlPar);
            HttpURLConnection connection = (HttpURLConnection) urlImage.openConnection();
            InputStream inputStream = connection.getInputStream();
            bitmap = BitmapFactory.decodeStream(inputStream);
            image.setImageBitmap(bitmap);
            connection.disconnect();
            inputStream.close();
        } catch (MalformedURLException e) {
            if(imageSuivant==true)
                imageSuivante();
            else
                imagePrecedente();
            e.printStackTrace();
        } catch (IOException e) {
            if(imageSuivant==true)
                imageSuivante();
            else 
                imagePrecedente();
            e.printStackTrace();
        }
    }
moujib
  • 742
  • 2
  • 7
  • 26
loulou8284
  • 15
  • 1
  • 8

3 Answers3

1

can you open the image whith the html-browser? if not the image-url is not reachable from the internet but only from wlan-intranet. (i.e. http://192.168.117.18/myImage.jpg is not reachable from internet (3G)

k3b
  • 14,517
  • 7
  • 53
  • 85
  • Thanks for your quick answer, I realized that the site is out now... So it doesn't work with wifi too. I tried an other image and it worked both wifi and 3g. Sorry for my useless question.. – loulou8284 May 09 '12 at 13:34
0

A few times I have found that my phone operator does not allow certain type of files to be accessed. For example it was impossible for me to get an archive file (.zip) from the web in 3G but it worked fine in Wifi. Maybe your problem is similar. Check your image file type and try with other types of files.

Ika
  • 1,608
  • 14
  • 15
0

Try

    conn.setDoOutput(true);

    connection.setAllowUserInteraction(true);

Hope this would help

Muhannad A.Alhariri
  • 3,702
  • 4
  • 30
  • 46