From 8c9728df957f1c1705aa86d5b341e6a58c3b0e29 Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Sun, 15 Jun 2025 12:09:32 +0600 Subject: [PATCH] manager: fix zip not flashing from content:// uri --- .../com/rifsxd/ksunext/ui/MainActivity.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt index f1cc4004..dbff9544 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt @@ -74,13 +74,29 @@ class MainActivity : ComponentActivity() { val isManager = Natives.becomeManager(ksuApp.packageName) if (isManager) install() - // Check if launched with a ZIP file val zipUri: Uri? = when (intent?.action) { Intent.ACTION_VIEW, Intent.ACTION_SEND -> { - intent.data ?: intent.getParcelableExtra(Intent.EXTRA_STREAM) + val uri = intent.data ?: intent.getParcelableExtra(Intent.EXTRA_STREAM) + uri?.let { + val name = when (it.scheme) { + "file" -> it.lastPathSegment ?: "" + "content" -> { + contentResolver.query(it, null, null, null, null)?.use { cursor -> + val nameIndex = cursor.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME) + if (cursor.moveToFirst() && nameIndex != -1) { + cursor.getString(nameIndex) + } else { + it.lastPathSegment ?: "" + } + } ?: (it.lastPathSegment ?: "") + } + else -> it.lastPathSegment ?: "" + } + if (name.lowercase().endsWith(".zip")) it else null + } } else -> null - }?.takeIf { it.toString().endsWith(".zip", ignoreCase = true) } + } setContent { // Read AMOLED mode preference