diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 88b5109f3..3cfe0af2e 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -6,6 +6,7 @@ import android.os.Build import android.os.Bundle import android.text.InputType import android.view.View +import androidx.documentfile.provider.DocumentFile import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference @@ -167,7 +168,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference when (requestCode) { oldDataRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { + DocumentFile.fromTreeUri(requireContext(), it)?.listFiles()?.forEach { + } } } } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt new file mode 100644 index 000000000..276cfa473 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -0,0 +1,31 @@ +package io.legado.app.utils + +import android.content.Context +import android.net.Uri + +object DocumentUtils { + + fun readText(context: Context, uri: Uri): String? { + readBytes(context, uri)?.let { + return String(it) + } + return null + } + + fun readBytes(context: Context, uri: Uri): ByteArray? { + try { + context.contentResolver.openInputStream(uri)?.let { + val len: Int = it.available() + val buffer = ByteArray(len) + it.read(buffer) + it.close() + return buffer + } + } catch (e: Exception) { + e.printStackTrace() + } + return null + } + + +} \ No newline at end of file