开发者

Make images and folder invisble to Gallery saved on SDcard?

开发者 https://www.devze.com 2023-04-04 20:26 出处:网络
Hi I want to make images invisible to android gallery or any third party gallery app, the image will be places in specific folder on SD card.

Hi I want to make images invisible to android gallery or any third party gallery app, the image will be places in specific folder on SD card.

For example I have following code to save an image to a folder called myimages. I just want the images stored in myimages folder should not be visible to any gallery app and only my own application can access these images.

void saveBitmap(Bitmap bmp)
{
    FileOutputStream os;
    String dirName = "/mvc/mvc/my开发者_开发百科iamges/";
            try {  
                if (android.os.Environment.getExternalStorageState().equals(
                        android.os.Environment.MEDIA_MOUNTED)){
                    String root = Environment.getExternalStorageDirectory()
                                          .toString();
                    File dir = new File (root + dirName);

                    boolean created=dir.mkdirs();
                    //File file = new File(this.getExternalFilesDir(null), 
                            //                     this.dirName+fileName); 
                            //this function give null pointer exception so im 
                            //using other one
                    File file = new File(dir, "aeg2.png");
                    os = new FileOutputStream(file);
                }else{
                    os = openFileOutput("aeg2.png", MODE_PRIVATE);
                }
                bmp.compress(CompressFormat.PNG, 100, os);

                os.flush();
                os.close();
            }catch(Exception e){
                e.printStackTrace();
            }
}


Rename those files with custom extensions like filename.extension.customextension

like hello.avi.topsecret.

When you need the file to be ready mode to play rename it to proper extension, play and rename it back.

This should work for you.

or

Prefix your folder name with a dot "."

Check these links for more info:

http://www.makeuseof.com/tag/hide-private-picture-folders-gallery-android/


Yes, save it with any extension you want or even without extension.

In your app, just read it as normal image file.


Create an empty file inside your image store folder named '.nomedia' <- atention to the initial point. All media files sabed inside this folder will not be showed in galery browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号