简体   繁体   中英

How to create a hidden folder i.e .MyFolder [(dot)MyFolder] in DCIM directory (Scoped Storage) Android Q

I want to create a hidden folder ieMyFolder [(dot)MyFolder] in DCIM directory. Here is my code:-

final String relativeLocation = Environment.DIRECTORY_DCIM+File.separator+".MyFolder/images";
        ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME,positionOfPager+".jpeg");
        contentValues.put(MediaStore.MediaColumns.MIME_TYPE,"image/*");
        contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,relativeLocation);
        imageUri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
        fos = (FileOutputStream) context.getContentResolver().openOutputStream(Objects.requireNonNull(imageUri));
        inImage.compress(Bitmap.CompressFormat.JPEG,100,fos);

The problem here is that a folder is create with Hyphen symbol "_.MyFolder" ie[(Hypen)(dot)MyFolder] due to which the folder is not hidden. My app is creating lots of images which i dont want to show up in gallery to bother the user. Please help me out Note:- I am implementing the code for scoped storage android 11

File file = new File( 
    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), ".MyFolder");

if ( ! file.existst() )
    if ( !file.mkdir() )
         return;

Both on 10 and 11 you can use this code.

You can also create your files using classic file system paths.

No need for MediaStore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM