From 0d0dc29c6e4b349fc67360e642dde1dd9e7eddd4 Mon Sep 17 00:00:00 2001 From: Daniel Woffinden Date: Sun, 2 Jan 2022 18:06:31 +0000 Subject: [PATCH] Android R+: request MANAGE_EXTERNAL_STORAGE when creating new git repos --- app/src/main/AndroidManifest.xml | 2 ++ .../com/orgzly/android/ui/repos/ReposActivity.kt | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f272521df..d2dd7507d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,8 @@ + + diff --git a/app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt b/app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt index efba405f5..cfbb250ef 100644 --- a/app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt +++ b/app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt @@ -1,9 +1,13 @@ package com.orgzly.android.ui.repos import android.Manifest +import android.content.Intent import android.content.pm.PackageManager +import android.net.Uri import android.os.Build import android.os.Bundle +import android.os.Environment +import android.provider.Settings import android.view.ContextMenu import android.view.MenuItem import android.view.View @@ -29,6 +33,7 @@ import com.orgzly.android.ui.showSnackbar import com.orgzly.databinding.ActivityReposBinding import javax.inject.Inject + /** * List of user-configured repositories. */ @@ -220,14 +225,18 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit } R.id.repos_options_menu_item_new_git -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - GitRepoActivity.start(this) - } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) { + val uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID) + startActivity( + Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri)) + } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // TODO: Show explanation why possibly, if ActivityCompat.shouldShowRequestPermissionRationale() says so? ActivityCompat.requestPermissions( this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE) + } else { + GitRepoActivity.start(this) } return }