How to create a hidden directory in android?

I am working on an application where I created some kind of directory that I access through my application. I want this directory to be hidden for security purposes. Thus, that the user can access them only inside the application, he does not access them outside the application as in the file manager. Any help is appreciated. Do not duplicate it, because I'm looking for the whole answer, but no one worked for me.

+4
source share
4 answers

Just add a dot before the folder name protects it . It is invisible to the user. It can still be obtained from applications, including file managers and, therefore, users. By default, this is simply hidden by most file managers.

As you want to hide files for security purposes, you should use the Android internal storage.

In the official Android developer guide:

You can save files directly to the internal memory of the device. By default, files stored in the internal storage are private to your application, and other applications cannot access them (and also cannot). When a user uninstalls your application, these files are deleted.

Example:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

Android Developer's Guide


Keystore Android.

android.
Android Keystore.

+2

" , " ( ) ,

-

public static File saveFileInAppDirectory(Context context,byte[] inpute, String directoryName,String fileName){
        File mypath;
        File directory = new File(context.getExternalFilesDir(
                Environment.DIRECTORY_PICTURES), directoryName);
        if (!directory.mkdirs()) {
            directory.mkdir();
        }
        mypath = new File(directory, fileName);
        try {
            InputStream is = new ByteArrayInputStream(inpute);
            FileOutputStream f = new FileOutputStream(mypath);
            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = is.read(buffer)) > 0) {
                f.write(buffer, 0, len1);
            }
            f.close();

        } catch (Exception e) {
            Log.e("SAVE_IMAGE", e.getMessage(), e);
            e.printStackTrace();
        }

        return mypath;
    } 

Path - Android/Data/Data/Your.Package.Name/FolderName/FileName

-

File mypath = new File(directory, "."+fileName);

,

new File(directory, fileName); with  new File(directory, "."+fileName);
+1

, (.) :

.myDir or .myDir1

. , (.) :

"/path/to/folder/.myDir/"

the same can be done for the file name

0
source

To hide a folder in Android

The name of your folder is MyApplicationFolder , then you need to add ( . ) Dot in front of the folder name, for example . MyApplicationFolder .

So, when the folder is created, the hidden mode folder for images, videos, etc. inside, but it will be visible in the FileManager.

0
source

Source: https://habr.com/ru/post/1664681/


All Articles