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.SET_WALLPAPER" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> <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.POST_NOTIFICATIONS" />
<uses-permission <uses-permission
android:name="android.permission.MANAGE_MEDIA" android:name="android.permission.MANAGE_MEDIA"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,9 @@
package com.simplemobiletools.gallery.pro.helpers package com.simplemobiletools.gallery.pro.helpers
import com.simplemobiletools.commons.helpers.MONTH_SECONDS 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 // shared preferences
const val DIRECTORY_SORT_ORDER = "directory_sort_order" 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_SQUARE = 1
const val FOLDER_STYLE_ROUNDED_CORNERS = 2 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.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import androidx.exifinterface.media.ExifInterface
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import androidx.exifinterface.media.ExifInterface
import com.simplemobiletools.commons.extensions.* 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.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isNougatPlus 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.config
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem 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.PhotoEditorSettingsList
import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic
import ly.img.android.pesdk.assets.font.basic.FontPackBasic import ly.img.android.pesdk.assets.font.basic.FontPackBasic
@ -62,7 +62,7 @@ class NewPhotoEditActivity : SimpleActivity() {
return return
} }
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(getPermissionToRequest()) {
if (it) { if (it) {
initEditActivity() initEditActivity()
} else { } 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.config
import com.simplemobiletools.gallery.pro.extensions.fixDateTaken import com.simplemobiletools.gallery.pro.extensions.fixDateTaken
import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem 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.VideoEditorSettingsList
import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic
import ly.img.android.pesdk.assets.font.basic.FontPackBasic import ly.img.android.pesdk.assets.font.basic.FontPackBasic
@ -56,7 +57,7 @@ class NewVideoEditActivity : SimpleActivity() {
return return
} }
handlePermission(PERMISSION_WRITE_STORAGE) { handlePermission(getPermissionToRequest()) {
if (it) { if (it) {
initEditActivity() initEditActivity()
} else { } else {