Skip to content

Commit be277c0

Browse files
committed
Request storage permission on app launch
Automatically prompts for "All files access" (Android 11+) or READ/WRITE_EXTERNAL_STORAGE (older) when the app starts, so /sdcard is accessible in proot without needing to manually go to Settings. Co-Authored-By: Mithun Gowda B <mithungowda.b7411@gmail.com>
1 parent 1082f22 commit be277c0

File tree

1 file changed

+25
-0
lines changed
  • flutter_app/android/app/src/main/kotlin/com/nxg/openclawproot

1 file changed

+25
-0
lines changed

flutter_app/android/app/src/main/kotlin/com/nxg/openclawproot/MainActivity.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ class MainActivity : FlutterActivity() {
475475

476476
createUrlNotificationChannel()
477477
requestNotificationPermission()
478+
requestStoragePermissionOnLaunch()
478479

479480
EventChannel(flutterEngine.dartExecutor.binaryMessenger, EVENT_CHANNEL).setStreamHandler(
480481
object : EventChannel.StreamHandler {
@@ -502,6 +503,30 @@ class MainActivity : FlutterActivity() {
502503
}
503504
}
504505

506+
private fun requestStoragePermissionOnLaunch() {
507+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
508+
if (!Environment.isExternalStorageManager()) {
509+
try {
510+
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
511+
startActivity(intent)
512+
} catch (_: Exception) {}
513+
}
514+
} else {
515+
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
516+
!= PackageManager.PERMISSION_GRANTED
517+
) {
518+
ActivityCompat.requestPermissions(
519+
this,
520+
arrayOf(
521+
Manifest.permission.READ_EXTERNAL_STORAGE,
522+
Manifest.permission.WRITE_EXTERNAL_STORAGE
523+
),
524+
STORAGE_PERMISSION_REQUEST
525+
)
526+
}
527+
}
528+
}
529+
505530
private fun createUrlNotificationChannel() {
506531
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
507532
val channel = NotificationChannel(

0 commit comments

Comments
 (0)