1

画像をダウンロードした後、この場所に保存します

 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フォルダーをギャラリーに表示します。

4

1 に答える 1

2

メディアスキャナーは、デバイスの電源がオンになっている場合、またはSDカードがホストPCからマウント解除されている場合を除いて、SDカードを自動的にスキャンしません。

メディアスキャナーで特にオンデマンドでスキャンを実行する場合は、を使用しますMediaScannerConnection

于 2010-11-26T20:57:08.110 に答える