[Android]ImageSwitcher setando imagens da URL

6 respostas
R

Bom dia, Pessoal

Tenho o seguinte problema, preciso setar as imagens em um componente ImageSwitcher via URL, fazer funcionar o componente ImageSwitcher com as imagens da pasta
drawable sem problemas.

Agora o grande problema é como setar via URL.

Obrigado

6 Respostas

Marky.Vasconcelos

Baixa a imagem pro device e coloca na tela?

Lembre-se de fazer isto em uma worker thread para não receber um NetworkOnMainThreadException

R

O problema é q nao posso baixar as imagens para o aparelho, existe algum jeito de fazer sem baixar as imagens?

Marky.Vasconcelos
Bitmap bmp = BitmapFactory.decodeStream(streamDaInternet);
R

Achei esse codigo na net, mas nao esta dando certo esta dando exceção.

private Bitmap fetchImage(String urlstr){
		    InputStream is= null;
		    Bitmap bm= null;
		    try{
		        HttpGet httpRequest = new HttpGet(urlstr);//bitmapUrl.toURI());
		        HttpClient httpclient = new DefaultHttpClient();
		        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

		        HttpEntity entity = response.getEntity();
		        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
		        is = bufHttpEntity.getContent();
		        bm = BitmapFactory.decodeStream(is); 
		    }catch ( MalformedURLException e ){
		        Log.d( "RemoteImageHandler", "fetchImage passed invalid URL: " + urlstr );
		    }catch ( IOException e ){
		        Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
		    }finally{
		        if(is!=null)try{
		            is.close();
		        }catch(IOException e){}
		    }
		    return bm;
		}

Vc tem algum exemplo de como fazer isso?

Obrigado

Marky.Vasconcelos

Qual exception?

NetworkOnMainThreadException? Eu já comentei para fazer isso em uma worker thread.

R

Não…

java.net.UnknownHostException:

as permissoes do manifest



Criado 18 de julho de 2012
Ultima resposta 18 de jul. de 2012
Respostas 6
Participantes 2