// Crear un objeto para subclase de AsyncTask
GetXMLTask task = new GetXMLTask();
// ejecutar la tarea
task.execute(new String[] { "ImageURL" });
// entonces en la clase Asyntask asignar la imagen a la vista de imagen para evitar android.os.NetworkOnMainThreadException
private class GetXMLTask extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... urls) {
Bitmap map = null;
for (String url : urls) {
map = downloadImage(url);
}
return map;
}
// Sets the Bitmap returned by doInBackground
@Override
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
// Creates Bitmap from InputStream and returns it
private Bitmap downloadImage(String url) {
Bitmap bitmap = null;
InputStream stream = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
try {
stream = getHttpConnection(url);
bitmap = BitmapFactory.
decodeStream(stream, null, bmOptions);
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
// Makes HttpURLConnection and returns InputStream
private InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
}
Espero, usted está recibiendo Skia Decoder Devuelto falso, asegúrese de que está entregando este mensaje o no, consulte Su Logcat, para este mensaje ???? –
@Sankar: ya he comprobado el logcat, estoy __NOT__ "recibiendo el mensaje Skia Decoder Returned false". – Sen
Entonces dime qué mensajes, tienes en tu Logcat? –