2
Through an application it is possible to create, edit and remove both files and directories, but we know that it is necessary for the user to give permission to read and write depending on the occasion. In order for this permission to be granted, you should normally enter a tag <users-permission />
in the <manifest></manifest>
, as an example READ_EXTERNAL_STORAGE
and WRITE_EXTERNAL_STORAGE
.
See below for a simple command to create a directory:
File dir = new File(context.getExternalFilesDir(Environment.DIRECTORY_DCIM), filename );
if (!dir.exists()) {
dir.getParentFile().mkdirs();
}
After all the procedure done, inserting documents and images inside this directory, when accessing a file manager/gallery, whether it is native to the smartphone or not, the user can see these files normally.
I have an application where I would like to view these documents only within it, so the way it is today, the files can also be viewed through the gallery.
You can create a protected directory on Storage of the device? Is there any other way to solve this problem, so that the user can not visualize the files outside of the application, or view only through a password?
How do you get the
path
that uses innew File(path)
?– ramaral
@ramaral I put this code only as an example. Do you think it is relevant to ask the question?!
– viana
That is why it will determine whether the directory is private or not. I will put a response.
– ramaral
One simple way is to leave the directory with a dot before the name, example. ". Appx". This keeps the directory hidden, and prevents the gallery and native explorers from finding the directory or files inside. Only some applications that have root permission and the option to view hidden files.
– Murillo Comino
Why are you wearing DIRECTORY_DCIM? It makes no sense since it refers to the parent folder of public folders.
– ramaral
@ramaral I had put only as an example for you have charged. I am actually creating a directory with name
apptal
inside/mnt/sdcard/
. So it’s really getting like this/mnt/sdcard/apptal
– viana
You should not use written paths. You have tried using
getExternalFilesDir()
with for example DIRECTORY_PICTURES? That is how I would check whether what I say in the reply is true and that the documentation is right(it is not always).– ramaral