require the proper permission on Android 13

This commit is contained in:
tibbi 2022-09-03 15:39:44 +02:00
parent 1461570bbf
commit 1c06d3c694
9 changed files with 20 additions and 13 deletions

View File

@ -13,6 +13,8 @@
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.MANAGE_MEDIA"

View File

@ -98,7 +98,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
setupOptionsMenu()
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (!it) {
toast(R.string.no_storage_permissions)
finish()

View File

@ -159,7 +159,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
private fun handleMediaPermissions(callback: (granted: Boolean) -> Unit) {
handlePermission(PERMISSION_WRITE_STORAGE) { granted ->
handlePermission(getPermissionToRequest()) { granted ->
callback(granted)
if (granted && isRPlus()) {
handlePermission(PERMISSION_MEDIA_LOCATION) {}
@ -445,7 +445,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun checkOTGPath() {
ensureBackgroundThread {
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
if (!config.wasOTGHandled && hasPermission(getPermissionToRequest()) && hasOTGConnected() && config.OTGPath.isEmpty()) {
getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply {
config.wasOTGHandled = true
val otgPath = trimEnd('/')
@ -474,7 +474,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private fun tryLoadGallery() {
// avoid calling anything right after granting the permission, it will be called from onResume()
val wasMissingPermission = config.appRunCount == 1 && !hasPermission(PERMISSION_WRITE_STORAGE)
val wasMissingPermission = config.appRunCount == 1 && !hasPermission(getPermissionToRequest())
handleMediaPermissions {
if (wasMissingPermission) {
return@handleMediaPermissions

View File

@ -393,7 +393,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
}
private fun tryLoadGallery() {
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (it) {
val dirName = when {
mPath == FAVORITES -> getString(R.string.favorites)

View File

@ -47,7 +47,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
setupOptionsMenu()
refreshMenuItems()
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (it) {
checkIntent(savedInstanceState)
} else {

View File

@ -101,7 +101,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
checkNotchSupport()
(MediaActivity.mMedia.clone() as ArrayList<ThumbnailItem>).filterIsInstanceTo(mMediaFiles, Medium::class.java)
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (it) {
initViewPager()
} else {
@ -115,7 +115,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
override fun onResume() {
super.onResume()
if (!hasPermission(PERMISSION_WRITE_STORAGE)) {
if (!hasPermission(getPermissionToRequest())) {
finish()
return
}

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.gallery.pro.helpers
import com.simplemobiletools.commons.helpers.MONTH_SECONDS
import com.simplemobiletools.commons.helpers.isQPlus
import com.simplemobiletools.commons.helpers.PERMISSION_READ_MEDIA_IMAGES
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isTiramisuPlus
// shared preferences
const val DIRECTORY_SORT_ORDER = "directory_sort_order"
@ -244,3 +246,5 @@ const val FOLDER_MEDIA_CNT_NONE = 3
const val FOLDER_STYLE_SQUARE = 1
const val FOLDER_STYLE_ROUNDED_CORNERS = 2
fun getPermissionToRequest() = if (isTiramisuPlus()) PERMISSION_READ_MEDIA_IMAGES else PERMISSION_WRITE_STORAGE

View File

@ -3,13 +3,12 @@ package com.simplemobiletools.gallery.pro.activities
import android.annotation.TargetApi
import android.app.Activity
import android.content.Intent
import androidx.exifinterface.media.ExifInterface
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import androidx.exifinterface.media.ExifInterface
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isNougatPlus
@ -20,6 +19,7 @@ import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem
import com.simplemobiletools.gallery.pro.helpers.getPermissionToRequest
import ly.img.android.pesdk.PhotoEditorSettingsList
import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic
import ly.img.android.pesdk.assets.font.basic.FontPackBasic
@ -62,7 +62,7 @@ class NewPhotoEditActivity : SimpleActivity() {
return
}
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (it) {
initEditActivity()
} else {

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog
import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem
import com.simplemobiletools.gallery.pro.helpers.getPermissionToRequest
import ly.img.android.pesdk.VideoEditorSettingsList
import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic
import ly.img.android.pesdk.assets.font.basic.FontPackBasic
@ -56,7 +57,7 @@ class NewVideoEditActivity : SimpleActivity() {
return
}
handlePermission(PERMISSION_WRITE_STORAGE) {
handlePermission(getPermissionToRequest()) {
if (it) {
initEditActivity()
} else {