我的 Android 应用程序可以下载图像,但没有出现在图库中
下载图像后,它将它们保存到这个位置,
String extStorageDirectory;
protected void onCreate(Bundle icicle) {
extStorageDirectory = Environment.getExternalStorageDirectory().toString(); //set it to the SD card directory
}
public void savetoSD(Integer Index) //Index is what pic number it is 1 through 9
{
OutputStream outStream = null;
String filename = "Hentai" + System.currentTimeMillis() + ".JPEG";
String filepath = extStorageDirectory + "/media/pictures/MyAppsDownloadFolder/" + filename;
File file = new File(filepath);
try {
outStream = new FileOutputStream(file);
//get a download here for the real bitmap
DownloadFromUrl(myMainPicURL[Index],filename);
Bitmap saveME = null;
saveME = BitmapFactory.decodeFile(PATH+filename);
saveME.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//need to refresh the damned MediaScanner
try {
MediaStore.Images.Media.insertImage(getContentResolver(), filepath, filename, "myDownloadedPics");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
message_user("Saved as " + filepath);
}
我相信媒体存储不起作用,或者我不知道如何使用它,请帮助
我希望下载的图像出现在图库中,或者至少有文件夹 MyAppsDownloadFolder 在图库中显示,但它没有!
After downloading images it saves them to this location
String extStorageDirectory;
protected void onCreate(Bundle icicle) {
extStorageDirectory = Environment.getExternalStorageDirectory().toString(); //set it to the SD card directory
}
public void savetoSD(Integer Index) //Index is what pic number it is 1 through 9
{
OutputStream outStream = null;
String filename = "Hentai" + System.currentTimeMillis() + ".JPEG";
String filepath = extStorageDirectory + "/media/pictures/MyAppsDownloadFolder/" + filename;
File file = new File(filepath);
try {
outStream = new FileOutputStream(file);
//get a download here for the real bitmap
DownloadFromUrl(myMainPicURL[Index],filename);
Bitmap saveME = null;
saveME = BitmapFactory.decodeFile(PATH+filename);
saveME.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//need to refresh the damned MediaScanner
try {
MediaStore.Images.Media.insertImage(getContentResolver(), filepath, filename, "myDownloadedPics");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
message_user("Saved as " + filepath);
}
I believe the mediastore doesnt work or i dont know how to use it please help
I want the downloaded images to appear in the gallery or atleast have the folder MyAppsDownloadFolder to show in the gallery which it doesnt!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
媒体扫描仪不会自动扫描 SD 卡,除非设备已打开或 SD 卡从主机 PC 上卸载。
如果您希望媒体扫描仪专门按需进行扫描,请使用
MediaScannerConnection
。The media scanner does not automatically scan the SD card, except when the device is turned on or the SD card is unmounted from the host PC.
If you want the media scanner to specifically do a scan on demand, use
MediaScannerConnection
.