我的目標是從給定的網址下載多個圖像並將它們保存到內存中。從url加載圖片到內部存儲
private void downloadImages(List<String> filename,JSONObject c) throws Exception{
String fileName = c.getString("name") + ".json";
String data = "";
File images = getDir("Images", Context.MODE_PRIVATE);
File dir = new File(images,fileName);
System.out.println(dir.getAbsolutePath());
List<Bitmap> pictures = new ArrayList<>();
for(String s : filename){
}
}
該List<String> filename
包含圖像的所有網址。 所以我想我需要做的是,下載圖像的每個網址在filename
的結構是這樣的:
Images
------fileName
--------------Image1
--------------Image2
------fileName2
--------------Image1
--------------Image2
我想用這樣的:
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://example.com/file.png", new FileAsyncHttpResponseHandler(/* Context */ this) {
@Override
public void onSuccess(int statusCode, Header[] headers, File response) {
// Do something with the file `response`
}
});
你的問題是什麼?你制定的方法不能按預期工作嗎?你試過了嗎? – vdelricco
我的問題是,我必須在foreach中將下載的圖像保存在我想要的結構中。這意味着 - >使用JSONObject的名稱創建子文件夾,並在那裏存儲每個圖像。 – greedsin