open file manager opens directory provider

This commit is contained in:
qimiko committed 2024-01-19 17:39:43 -07:00
1 parent ac8db3a98c
commit c13136de52
2 files changed
+20 -4

No files matched your search

@@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.provider.DocumentsContract
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.OnBackPressedDispatcher
@@ -110,9 +111,21 @@ fun onOpenFolder(context: Context) {
}
fun onOpenFileManager(context: Context) {
// future thoughts: Intent.ACTION_VIEW may not work on some devices
// the "correct" solution is to go through a list of possible intents/applications
// don't feel like writing that behavior. this is good enough
val intent = Intent(Intent.ACTION_VIEW).apply {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
type = "vnd.android.document/directory"
data = DocumentsContract.buildRootUri(
"${context.packageName}.user",
UserDirectoryProvider.ROOT
)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
Intent.FLAG_GRANT_PREFIX_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
)
}
try {
@@ -11,8 +11,6 @@ import android.webkit.MimeTypeMap
import com.geode.launcher.utils.LaunchUtils
import java.io.File
private const val ROOT = "root"
private val DEFAULT_ROOT_PROJECTION: Array<String> = arrayOf(
DocumentsContract.Root.COLUMN_ROOT_ID,
DocumentsContract.Root.COLUMN_FLAGS,
@@ -30,7 +28,12 @@ private val DEFAULT_DOCUMENT_PROJECTION: Array<String> = arrayOf(
DocumentsContract.Document.COLUMN_SIZE
)
// a lot of this code is pulled from <https://github.com/dolphin-emu/dolphin>
class UserDirectoryProvider : DocumentsProvider() {
companion object {
internal const val ROOT = "root"
}
private lateinit var rootDir: File
override fun onCreate(): Boolean {