我的Android应用程序可以下载图像,但不会出现在图库中

时间:2010-11-26 20:07:56

标签: android download image mediastore

下载图像后,将它们保存到此位置

 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在图库中显示它不会!

1 个答案:

答案 0 :(得分:2)

介质扫描仪不会自动扫描SD卡,除非打开设备或从主机PC卸载SD卡。

如果您希望媒体扫描程序专门按需扫描,请使用MediaScannerConnection