How to keep images private to the app and not viewable in the gallery?

后端 未结 3 1597
长发绾君心
长发绾君心 2021-02-11 04:02

I am making an app to click pics and save that images in app folder.I want my images to be private to application only and not viewable in gallery. But with the code I have writ

相关标签:
3条回答
  • 2021-02-11 04:40

    You should not be using Environment.getExternalStoragePublicDirectory() to get the directory for your images. As the method's name implies, it will return a public directory.

    To get your app's private data directory, you can call Context.getFilesDir().

    See here for a guide that provides more information about writing app-private files.

    0 讨论(0)
  • 2021-02-11 04:54

    Add empty file with name ".nomedia" in this folder. Then MediaStore will not scan this folder.

    Also if you want to show to user media only from certain folder, you can use my small and simple open source library. Check TestActivity to see how to use that.

    0 讨论(0)
  • 2021-02-11 04:57

    One way is to to name your images directory with a name that starts with a period, that will hide the images from the media scanners. So in your case the name might be ".Car Camera".

    Alternatively, you can put an empty file in the directory (alongside your images) with the name ".nomedia".

    Here's a link that describes these options it a bit more.

    0 讨论(0)
提交回复
热议问题