gpt4 book ai didi

android - 如何在 android 11 的/Android/media 中创建文件夹?

转载 作者:行者123 更新时间:2023-12-04 23:39:54 30 4
gpt4 key购买 nike

我想在内部存储中创建一个新文件夹。但是在新版本的Android中,我们不能像之前创建的那样创建文件夹。但是像 WhatsApp 这样的一些应用程序会在/Android/media/中创建文件夹。我想知道我们如何在这个位置创建文件夹

最佳答案

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.

关于android - 如何在 android 11 的/Android/media 中创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69658332/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com