Rotiv
Julho 18, 2012, 10:17am
#1
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
Baixa a imagem pro device e coloca na tela?
Lembre-se de fazer isto em uma worker thread para não receber um NetworkOnMainThreadException
Rotiv
Julho 18, 2012, 11:50am
#3
O problema é q nao posso baixar as imagens para o aparelho, existe algum jeito de fazer sem baixar as imagens?
Bitmap bmp = BitmapFactory.decodeStream(streamDaInternet);
Rotiv
Julho 18, 2012, 1:14pm
#5
Achei esse codigo na net, mas nao esta dando certo esta dando exceção.
[code]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;
}[/code]
Vc tem algum exemplo de como fazer isso?
Obrigado
Qual exception?
NetworkOnMainThreadException? Eu já comentei para fazer isso em uma worker thread.
Rotiv
Julho 18, 2012, 3:23pm
#7
Não…
java.net.UnknownHostException:
as permissoes do manifest