diff --git a/app/build.gradle b/app/build.gradle index 4eda6bd4..47e71194 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,12 +46,12 @@ android { release } - compileSdk 32 + compileSdk 33 defaultConfig { applicationId "com.amaze.fileutilities" minSdk 21 - targetSdk 32 + targetSdk 33 Integer sudoVersionCode = 29 String versionNameText = "1.89" diff --git a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt index b2cbb895..18717c4c 100644 --- a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt +++ b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt @@ -21,6 +21,7 @@ package com.amaze.fileutilities import android.Manifest +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -54,22 +55,22 @@ open class PermissionsActivity : * Invokes permission check when we don't show welcome screen. */ fun invokePermissionCheck() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkStoragePermission()) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) { requestStoragePermission(onPermissionGranted, true) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.R) { requestAllFilesAccess(onPermissionGranted) } } } fun haveStoragePermissions(): Boolean { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkStoragePermission()) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) { return false } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + if (VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager() ) { return false @@ -176,7 +177,7 @@ open class PermissionsActivity : } fun initLocationResources(onPermissionGranted: OnPermissionGranted) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkLocationPermission()) { + if (VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkLocationPermission()) { val builder: AlertDialog.Builder = this.let { AlertDialog.Builder(this, R.style.Custom_Dialog_Dark) } @@ -296,7 +297,7 @@ open class PermissionsActivity : * @param onPermissionGranted permission granted callback */ private fun requestAllFilesAccess(onPermissionGranted: OnPermissionGranted) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && + if (VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager() ) { val builder: AlertDialog.Builder = this.let { @@ -315,11 +316,23 @@ open class PermissionsActivity : permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted try { val intent = - Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) .setData(Uri.parse("package:$packageName")) startActivity(intent) + } catch (anf: ActivityNotFoundException) { + // fallback + log.warn("Failed to find activity for all files access", anf) + try { + val intent = + Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + .setData(Uri.parse("package:$packageName")) + startActivity(intent) + } catch (e: Exception) { + log.error("Failed to initial activity to grant all files access", e) + applicationContext.showToastInCenter(getString(R.string.grantfailed)) + } } catch (e: Exception) { - log.error("Failed to initial activity to grant all files access", e) + log.error("Failed to grant all files access", e) applicationContext.showToastInCenter(getString(R.string.grantfailed)) } dialog.cancel() diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/PermissionFragmentWelcome.kt b/app/src/main/java/com/amaze/fileutilities/home_page/PermissionFragmentWelcome.kt index fde9d97c..93335091 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/PermissionFragmentWelcome.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/PermissionFragmentWelcome.kt @@ -61,7 +61,7 @@ class PermissionFragmentWelcome : Fragment() { val activity = requireActivity() as WelcomeScreen activity.run { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkStoragePermission()) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) { requestStoragePermission(onPermissionGranted, true) } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt index b6da2026..593c964b 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt @@ -21,6 +21,7 @@ package com.amaze.fileutilities.home_page import android.Manifest +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.content.pm.PackageManager @@ -56,7 +57,7 @@ abstract class WelcomePermissionScreen : fun haveStoragePermissions(): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!checkStoragePermission()) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) { return false } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && @@ -311,11 +312,23 @@ abstract class WelcomePermissionScreen : permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted try { val intent = - Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) .setData(Uri.parse("package:$packageName")) startActivity(intent) + } catch (anf: ActivityNotFoundException) { + // fallback + log.warn("Failed to find activity for all files access", anf) + try { + val intent = + Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + .setData(Uri.parse("package:$packageName")) + startActivity(intent) + } catch (e: Exception) { + log.error("Failed to initial activity to grant all files access", e) + applicationContext.showToastInCenter(getString(R.string.grantfailed)) + } } catch (e: Exception) { - log.error("Failed to initial activity to grant all files access", e) + log.error("Failed to grant all files access", e) applicationContext.showToastInCenter(getString(R.string.grantfailed)) } dialog.cancel()