forked from geode-sdk/android-launcher
open file manager opens directory provider
This commit is contained in:
2 files changed
+20
-4
No files matched your search
@@ -8,6 +8,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.DocumentsContract
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.OnBackPressedDispatcher
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
@@ -110,9 +111,21 @@ fun onOpenFolder(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenFileManager(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 {
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
data = DocumentsContract.buildRootUri(
|
||||||
type = "vnd.android.document/directory"
|
"${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 {
|
try {
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import android.webkit.MimeTypeMap
|
|||||||
import com.geode.launcher.utils.LaunchUtils
|
import com.geode.launcher.utils.LaunchUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
private const val ROOT = "root"
|
|
||||||
|
|
||||||
private val DEFAULT_ROOT_PROJECTION: Array<String> = arrayOf(
|
private val DEFAULT_ROOT_PROJECTION: Array<String> = arrayOf(
|
||||||
DocumentsContract.Root.COLUMN_ROOT_ID,
|
DocumentsContract.Root.COLUMN_ROOT_ID,
|
||||||
DocumentsContract.Root.COLUMN_FLAGS,
|
DocumentsContract.Root.COLUMN_FLAGS,
|
||||||
@@ -30,7 +28,12 @@ private val DEFAULT_DOCUMENT_PROJECTION: Array<String> = arrayOf(
|
|||||||
DocumentsContract.Document.COLUMN_SIZE
|
DocumentsContract.Document.COLUMN_SIZE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// a lot of this code is pulled from <https://github.com/dolphin-emu/dolphin>
|
||||||
class UserDirectoryProvider : DocumentsProvider() {
|
class UserDirectoryProvider : DocumentsProvider() {
|
||||||
|
companion object {
|
||||||
|
internal const val ROOT = "root"
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var rootDir: File
|
private lateinit var rootDir: File
|
||||||
|
|
||||||
override fun onCreate(): Boolean {
|
override fun onCreate(): Boolean {
|
||||||
|
|||||||
Reference in new issue
Block a user