Skip to content

Commit

Permalink
fix(ContextExtension): update permissions handling for Android Q and …
Browse files Browse the repository at this point in the history
…above (fix #337) (#338)

Refactored the permissions check logic to correctly handle scoped storage for devices running Android Q and later. Removed redundant code and ensured proper invocation of permission grants.

# GENERATE BY https://aicommit.app
  • Loading branch information
rosuH authored Sep 13, 2024
1 parent b5c9148 commit 7e77cae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
tools:ignore="ScopedStorage" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ fun Activity.checkWritingPermission(
},
grant: () -> Unit,
) {
val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Manifest.permission.READ_MEDIA_IMAGES
} else {
Manifest.permission.WRITE_EXTERNAL_STORAGE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
grant.invoke()
return
}
preCheckStoragePermission(activityResultLauncher, permissions, failed, grant)
preCheckStoragePermission(activityResultLauncher, Manifest.permission.WRITE_EXTERNAL_STORAGE, failed, grant)
}

fun Activity.preCheckStoragePermission(
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ android.nonFinalResIds=false

majorVersion=2
minorVersion=9
patchVersion=3
patchVersion=4

0 comments on commit 7e77cae

Please sign in to comment.