Skip to content

Commit 4bbec3d

Browse files
committed
Permission check fix for GitRepoActivity
1 parent 990594e commit 4bbec3d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.orgzly.android.ui.repos
22

33
import android.Manifest
44
import android.content.pm.PackageManager
5+
import android.os.Build
56
import android.os.Bundle
67
import android.view.ContextMenu
78
import android.view.MenuItem
@@ -199,7 +200,7 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
199200
when (requestCode) {
200201
ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE -> {
201202
val granted = grantResults.zip(permissions)
202-
.find { (_, perm) -> perm == READ_WRITE_EXTERNAL_STORAGE }
203+
.find { (_, perm) -> perm == Manifest.permission.WRITE_EXTERNAL_STORAGE }
203204
?.let { (grantResult, _) -> grantResult == PackageManager.PERMISSION_GRANTED }
204205
if (granted == true) {
205206
GitRepoActivity.start(this)
@@ -216,11 +217,14 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
216217
}
217218

218219
R.id.repos_options_menu_item_new_git -> {
219-
if (ContextCompat.checkSelfPermission(this, READ_WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
220+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
220221
GitRepoActivity.start(this)
221222
} else {
222223
// TODO: Show explanation why possibly, if ActivityCompat.shouldShowRequestPermissionRationale() says so?
223-
ActivityCompat.requestPermissions(this, arrayOf(READ_WRITE_EXTERNAL_STORAGE), ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE)
224+
ActivityCompat.requestPermissions(
225+
this,
226+
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
227+
ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE)
224228
}
225229
return
226230
}
@@ -273,7 +277,6 @@ class ReposActivity : CommonActivity(), AdapterView.OnItemClickListener, Activit
273277
companion object {
274278
val TAG: String = ReposActivity::class.java.name
275279

276-
const val READ_WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE
277280
const val ACTIVITY_REQUEST_CODE_FOR_READ_WRITE_EXTERNAL_STORAGE = 0
278281
}
279282
}

0 commit comments

Comments
 (0)