Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在手机的内部共享文件夹中创建类似whatsApp的文件夹?_Android_Kotlin_Directory - Fatal编程技术网

Android 如何在手机的内部共享文件夹中创建类似whatsApp的文件夹?

Android 如何在手机的内部共享文件夹中创建类似whatsApp的文件夹?,android,kotlin,directory,Android,Kotlin,Directory,我想在内部共享文件夹中创建我的应用程序文件夹。我试过了,但它的文件夹正在Android文件夹中创建。 路径是 内部共享文件夹->Android文件夹->所有软件包文件夹->我的应用程序文件夹 我想直接在内部共享文件夹中创建文件夹。我怎样才能在科特林做到这一点 下面是我尝试过的代码: fun createApplicationFolders(context: Context) { val directoryPath = context.getFilesDir().getAbsol

我想在内部共享文件夹中创建我的应用程序文件夹。我试过了,但它的文件夹正在Android文件夹中创建。 路径是

内部共享文件夹->Android文件夹->所有软件包文件夹->我的应用程序文件夹

我想直接在内部共享文件夹中创建文件夹。我怎样才能在科特林做到这一点

下面是我尝试过的代码:

fun createApplicationFolders(context: Context) {

        val directoryPath = context.getFilesDir().getAbsolutePath()
        val rootFolder = context.getExternalFilesDir(context.getString(R.string.myapp))
        val rootFolderPath =
            File(directoryPath + File.separatorChar + context.getString(R.string.myapp))

        if (!rootFolder!!.exists()) {
            rootFolderPath.mkdir()
            for (folder in context.getResources().getStringArray(R.array.folderArray)) {
                val newFolder = File(rootFolder.absolutePath, folder)
                if (!newFolder.exists()) {
                    newFolder.mkdir()
                }
            }
        } else {
            for (folder in context.getResources().getStringArray(R.array.folderArray)) {
                val newFolder = File(rootFolder.absolutePath, folder)
                if (!newFolder.exists()) {
                    newFolder.mkdir()
                }
            }
        }
    }

抱歉,对于Android 11+来说,这不是一个实用的选项。如果您不喜欢
getExternalFilesDirs()
,请使用存储访问框架,让用户决定用户希望您的应用程序在用户设备上存储用户内容的位置。或者,也可以使用
MediaStore
。有关更多信息,请参阅。我可以获得任何示例来实现此功能吗?我不确定“this”到底指的是什么,也不确定在我在中提到的示例之外,您在寻找什么。内置的应用程序演示了
操作\u创建\u文档
(请参阅)。from演示如何通过
MediaStore
下载和存储视频。