我是一名新的Android開發人員,我正在開發一個應用程序,可以顯示來自url地址的圖像。它在wifi中工作正常,但在3g中不起作用。 下面的代碼:應用程序在wifi中正常工作,但在3g中不起作用
private void downloadImage(String urlPar, boolean imageSuivant) {
try {
URL urlImage = new URL(urlPar);
HttpURLConnection connection = (HttpURLConnection) urlImage.openConnection();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
image.setImageBitmap(bitmap);
connection.disconnect();
inputStream.close();
} catch (MalformedURLException e) {
if(imageSuivant==true)
imageSuivante();
else
imagePrecedente();
e.printStackTrace();
} catch (IOException e) {
if(imageSuivant==true)
imageSuivante();
else
imagePrecedente();
e.printStackTrace();
}
}
請添加一些logcat的跟蹤 – moujib
你的意思是「不工作」嗎?你得到如果是這樣,哪一個? – Nanne
感謝您的快速回答,問題來自網站。對不起,我沒用的問題.. – loulou8284