Android: 将图像保存到 SD 卡而不在图库中查看
Android: Save image to sd card without view in 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 卡但没有显示在图库中
在文件夹中添加 .nomedia 文件。
理解nomedia文件的概念Link
我使用此代码将图像保存到 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 卡但没有显示在图库中
在文件夹中添加 .nomedia 文件。
理解nomedia文件的概念Link