[使用Kotlin访问android api 29中的应用程序文件夹

问题描述 投票:1回答:1

[嗨,我无法像以前一样访问api 29中的应用程序文件夹我如何像以前一样在Android 29上使用应用程序文件夹?

fun _Path(context: Context?): String? {
        return 
            "/sdcard/test/" + Prefs(context!!).getServerIndex() + "/"

    }
android kotlin
1个回答
1
投票

由于Google访问权限和政策的更改,您不能再使用以前的方法。

如果您坚持像以前一样使用文件夹,则可以使用此方法

fun _Path(context: Context?): String? {
        return if (Build.VERSION.SDK_INT >= 29) { 
            context?.externalCacheDir!!.path + "/test/" + Prefs(context).getServerIndex() + "/"
        } else {
            "/sdcard/test/" + Prefs(context!!).getServerIndex() + "/"
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.