1

i want to ask that i am downloading images from url means i had url in string array and on button click i move to next url and downloaded image from server. it runs perfectly on samsung galaxy s2 mobile and image downloading and displaying in view but in some other mobile of small size screen it is not displaying in view but in some it displaying ...what is the reason behind this what is happening ..i use setimageBitmap() in onpostExecute() and it work well for samsung galaxys2 what about for lower range mobile why it is not displaying ..i also change the image view height and width but not solve..but some time it is displaying..

my code is below..

log cat:

  logcat out  put :



   DEBUG/skia(231): --- decoder->decode returned false
  INFO/System.out(231): Bitmap :: null
  INFO/System.out(231): Bitmap on post :: null
 WARN/InputManagerService(63): Window already focused, ignoring focus gain of:   com.android.internal.view.IInputMethodClient$Stub$Proxy@44c17828
INFO/System.out(231): Message sent
 INFO/image url/////(231):   http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/carlos_cruz-diez/carlos_cruz-diez2/507989-1-esl-AR/Carlos_Cruz-Diez.jpg
   INFO/System.out(231): Bitmap :: android.graphics.Bitmap@44d64750
     INFO/System.out(231): Bitmap on post :: android.graphics.Bitmap@44d64750
shyam
  • 1,276
  • 4
  • 25
  • 51

3 Answers3

1

try this for fetching Image ::

 ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.tran_btn_skip);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.hermann-uwe.de/files/images/blue_flower.preview_0.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

manifest permission:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

and try this in mobile device (not in emulator)if you load from your server but, if you load from any another server ten you can show in emulator.

Update::

see

package com.progressbar;

import java.io.InputStream;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageButton;
public class progressbar extends Activity  {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageButton   tran_btn_skip = (ImageButton) findViewById(R.id.login);

        try {
            Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
                    "http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/leila_tschopp3/baja-leila_tschopp_-_river_-acrilico_sobre_tela-130x150_cm_-_2011/498599-1-esl-AR/BAJA-Leila_Tschopp_-_River_-acrilico_sobre_tela-130x150_cm_-_2011.jpg")
                    .getContent());
            tran_btn_skip.setImageBitmap(bitmap);
        } catch (Exception e) {
        }

    }
    }
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
  • HEY ON PRINTING System.out.println("Bitmap :: " + bitmap);,bitmap value is null – shyam Sep 16 '11 at 11:00
  • first tell me are you getting from particular url or own n/w server – Nikunj Patel Sep 16 '11 at 11:02
  • please try my code i have update with temporary URL it is flower image just try in emulator – Nikunj Patel Sep 16 '11 at 11:07
  • but make sure you connection cant loose – Nikunj Patel Sep 16 '11 at 11:08
  • hi nick ur url is working and my url is http://www.artealdiaonline.com/var/artealdia_com/storage/images/argentina/agenda/exposiciones_muestras/carlos_cruz-diez/carlos_cruz-diez/507986-1-esl-AR/Carlos_Cruz-Diez.jpg is not working why? – shyam Sep 16 '11 at 11:14
  • iamge is showing from ur url but if i replace it with my then not...why? – shyam Sep 16 '11 at 11:15
  • http://www.arteonline.mobi/iphone/output.php?galleryID=4 in this url the tag for image url is "ImageExposiciones" i parse it collect url in array and use for downloading...u can also see it – shyam Sep 16 '11 at 12:12
  • just tell me in your android device, internet connectivity are come from USB? – Nikunj Patel Sep 16 '11 at 12:23
  • as i said it working on some emulator and problem in wqvga of 5554 emulator – shyam Sep 16 '11 at 12:25
  • means for small screen it is not working but ur image url is working fine – shyam Sep 16 '11 at 12:26
  • first tell me you have device or not?(i am angrily with your attitude) – Nikunj Patel Sep 16 '11 at 12:26
  • i have device LG Optimus One v 2.2 – shyam Sep 16 '11 at 12:29
  • are you get internet from Your pc or Wifi or 3g? – Nikunj Patel Sep 16 '11 at 12:33
  • internet from 3G in my mobile – shyam Sep 16 '11 at 12:34
  • i just help you because i have also face problem with emulator which i have load my own server file but when i have insert it in device it working fine main reason is network. you cant load image if you use network connection in device or pc – Nikunj Patel Sep 16 '11 at 12:34
  • as you show in screen short i have successfully load your image.so again check in manifest file that all permission are give and check correctly – Nikunj Patel Sep 16 '11 at 12:36
  • in my pc i am using network connection then also it is not working i am also wondering why image is display in one emulator and in other its not – shyam Sep 16 '11 at 12:37
  • nikunj wait i am sending u video url of my problem,so that u can see my problem in emulator – shyam Sep 17 '11 at 04:49
  • goto your project property >> click android >> and give me screen short of `Project Build Target` – Nikunj Patel Sep 17 '11 at 05:14
  • pls see my log cat output also in my qus. part above...thanks – shyam Sep 17 '11 at 05:20
  • choose android 2.2 target instead of google api if you are not use map – Nikunj Patel Sep 17 '11 at 05:20
  • nikunj actually i am using google map in my application so if i set target 2.2 then it will show error – shyam Sep 17 '11 at 05:21
  • means target target=Google Inc.:Google APIs:10 ?i have try it and its working well on it.so is there any problem for using google apis:7 .then if i will use apis level:10 then what should be the version of my mobile to run it and display downloaded image sucessfull?actully when i set target api:10 then also in my mobile image is not downloadin...but in my other mobile samsung galaxy s2 it works well... – shyam Sep 17 '11 at 05:28
  • hey nikunj pls see my new problem http://stackoverflow.com/questions/7452754/display-the-back-and-next-button-between-half-the-height-of-image-android can u also upvote my qus – shyam Sep 17 '11 at 05:53
0

Try this one:

   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
   conn.setDoInput(true);
   conn.setConnectTimeout(7000);
   conn.connect();
   BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
   Drawable drawable = Drawable.createFromStream(is, imageUrl);
   view.setImageBitmap(drawable)
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
0

Here is the complete code:

String imageUrl = "http://someurl.com/example.png";
URL url = new URL(imageUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(7000);
conn.connect();
BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
Drawable imageDrawable = Drawable.createFromStream(is, imageUrl);
view.setImageBitmap(imageDrawable);
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127