Android:将图像保存到SD卡而不在库中查看

时间:2016-05-18 09:03:45

标签: android gallery

我使用此代码将图像保存到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卡但未在图库中显示

1 个答案:

答案 0 :(得分:0)

在文件夹中添加 .nomedia 文件。

了解nomedia文件Link

的概念