'how to create folder inside /Android/media in android 11?
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | vaidik limbachiya |