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

发布于 2024-10-04 19:18:52 字数 1649 浏览 4 评论 0原文

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

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-10-11 19:18:52

媒体扫描仪不会自动扫描 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文