Reputation: 1306
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
Upvotes: 1
Views: 806
Reputation: 16120
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);
Upvotes: 0
Reputation: 22066
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::
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) {
}
}
}
Upvotes: 1
Reputation: 16120
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)
Upvotes: 0