Skip to content

Commit

Permalink
Android R+: request MANAGE_EXTERNAL_STORAGE when creating new git repos
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoffinden committed Jul 12, 2022
1 parent d00c039 commit 3d24ea0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<!-- For BroadcastReceiver below -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/orgzly/android/ui/repos/ReposActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -29,6 +33,7 @@ import com.orgzly.android.ui.showSnackbar
import com.orgzly.databinding.ActivityReposBinding
import javax.inject.Inject


/**
* List of user-configured repositories.
*/
Expand Down Expand Up @@ -219,14 +224,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
}
Expand Down

0 comments on commit 3d24ea0

Please sign in to comment.