Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create folder inside /Android/media in android 11?

Tags:

android

I want to create a new folder inside internal storage. But in the new version of Android, we can't create a folder as we created before. But some apps like WhatsApp create folders inside /Android/media/. I want to know about the way how we can create folders inside this location

like image 248
Dulaj Madusanka Avatar asked Mar 17 '26 15:03

Dulaj Madusanka


1 Answers

context.getExternalMediaDirs() will return you all the folders from media folder and when you call that it will create a folder with your app's package name all you have to do is identify packagename and get your folder path. This function will return you full path to your folder inside media folder. But it will not work for lollipop and less versions.

 public static String create_folder_in_app_package_media_dir_new2(Context context) {

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     File[] directory = new File[0];

     directory = context.getExternalMediaDirs();


 for(int i = 0;i<directory.length;i++){

         if(directory[i].getName().contains(context.getPackageName())){
             return directory[i].getAbsolutePath();
         }

     }

 }

     return null;
}

Note : If you delete or uninstall your application from device this folder will also be removed and data inside this folder will also be removed.

like image 122
vaidik limbachiya Avatar answered Mar 19 '26 05:03

vaidik limbachiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!