我使用此代码将图像保存到SD卡:
URL url = new URL(downloadPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int fileSize = connection.getContentLength();
int len = 0;
int downloadedSize = 0;
FileOutputStream outputStream = new FileOutputStream(filepath);
InputStream inputStream = connection.getInputStream();
byte[] buffer = new byte[G.DOWNLOAD_BUFFER_SIZE];
while ((len = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
downloadedSize += len;
downloadPercent = (float) (100.0 * (float) downloadedSize / fileSize);
}
outputStream.close();
但保存后,在画廊中显示
我想保存到SD卡但未在图库中显示