0

I want to show a hidden folder having a video file in it. I know that a folder in Internal Storage is not really hidden, it is not shown by file managers having names starting with dot"."

I am using Content Resolver and Media Store to fetch all the folders/directories having video files in them. My code is working fine in fetching video folders and files except that it doesn't folder name starting with dot "." even when I manually create a folder name e.g. " .hidden_folder " and put a video file in it, still, it is not fetched.

The code I am using to fetch all video files:

  @RequiresApi(api = Build.VERSION_CODES.O)
public ArrayList<MediaFiles> fetchMedia() {
    ArrayList<MediaFiles> mediaFilesArrayList = new ArrayList<>();
    Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
    Cursor cursor = getContentResolver().query(uri, null, null, null);

    if (cursor != null && cursor.moveToNext()) {
        do {
            String id = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media._ID));
            String title = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.TITLE));
            String displayName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
            String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
            String size = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.SIZE));
            String duration = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));
            String dateAdded = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATE_ADDED));

            MediaFiles mediaFiles = new MediaFiles(id, title, duration, size, dateAdded, path, displayName, false);

            int index = path.lastIndexOf("/");
            substring = path.substring(0, index);
            SharedPreferences sharedPreferences = getSharedPreferences(HIDDEN_VIDEOS_PREFS, MODE_PRIVATE);
            if (!allFolderList.contains(substring) && sharedPreferences.getString(HIDDEN_VIDEO_KEY + substring, "-") == ("-")) {
                allFolderList.add(substring); **// This is the list having folders**
            }
            mediaFilesArrayList.add(mediaFiles);
        }
        while (cursor.moveToNext());
    }
    return mediaFilesArrayList; **//This is the list containg vido files**
}

I am making a Video player App in which there is an option of showing hidden files and folders. I want to search the whole Internal storage and find if there is any hidden folder and have a video file in it.

settings image

When changing the name of the folder by putting a dot in the start by using a built-in file manager of the device, it is not shown in my app and when I rename it back to the original just by removing the dot, it is showing.

Is there a right way I can fetch the hidden folders ?... I have searched everywhere....but didn't found any solution...

Ali Zahid
  • 151
  • 2
  • 10
  • Please tell full path of your hidden folder. Also tell Android version of used device. – blackapps Oct 21 '21 at 11:37
  • The full path of hidden folder is: /storage/emulated/0/.hidden_folder and the device I am using is Android 11, Api 30 – Ali Zahid Oct 21 '21 at 11:41
  • How did your app create that folder there on external storage? On an Android 11 device this normally is not possible for an app. And did your app put that file there too? If your app did not create the file then your app will normally not see such files on an Android 11 device. – blackapps Oct 21 '21 at 11:43
  • I created the folder manaully by built in device file manager app. If rename the folder by removing dot from the folderName then it is showing otherwiese it is not showing in my app – Ali Zahid Oct 21 '21 at 11:45
  • Further: Let the app create folder and file itself. Let the file be scanned by the media scanner (otherwise no file will be visible in the media store). You will then see your file even if it is inh a 'hidden' folder. And what is 'manually'? – blackapps Oct 21 '21 at 11:46
  • My app doesn't have the functionality of creating files and folders. The thing is I just want to fetch the files from Internal Storage if there is already any e.g .Statuses folder containing whatsapp status videos – Ali Zahid Oct 21 '21 at 11:50
  • That is a quite different path and not /storage/emulated/0/.hidden_folder. You are confusing. You should have started this post with your whatsapp desire. – blackapps Oct 21 '21 at 11:51
  • that was just an example to test whether my app shows this folder or not. – Ali Zahid Oct 21 '21 at 11:52
  • I am making a video player app in which there is an option of showing hidden files and folders from the Internal Storage – Ali Zahid Oct 21 '21 at 11:54
  • Your problem has nothing to do with hidden files or folders. On an Android 11 device your app will not see files of other apps. Or files which you copied to your device 'manually'. – blackapps Oct 21 '21 at 11:57
  • but why it is shown when I just remove the dot from the folder name? – Ali Zahid Oct 21 '21 at 12:00
  • I did not test this scenario. Or... maybe the files were not scanned by the media scanner before. Did you let them scan? Think that the file manager ordered a scan on the whole directory.. Add that dot again and see.. I dont understand... – blackapps Oct 21 '21 at 12:08

0 Answers0