[英]Android download image from shorturl
我試圖從下載圖像這給短網址/從Facebook重定向,但在我的情況下,它不工作-我的繼承人的代碼:
private Bitmap getBitmap(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Bitmap btm = BitmapFactory.decodeStream(is);
is.close();
return btm;
}catch (MalformedURLException e) {
Log.v(Constants.LOG_TAG, "[Error] " + e + ": " + e.getMessage());
e.printStackTrace();
return null;
}catch (IOException e) {
Log.v(Constants.LOG_TAG, "[Error] " + e + ": " + e.getMessage());
e.printStackTrace();
return null;
}
}
嘗試改用http:
public Bitmap getBitmapFromURL(String src) {
try {
java.net.URL url = new java.net.URL(src);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
或嘗試使用以下庫之一,例如:
Android Universal Image Loader: https : //github.com/nostra13/Android-Universal-Image-Loader
離子: https : //github.com/koush/ion
滑行: https : //github.com/bumptech/glide
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.