diff --git a/templates/java/statics/android-uploader/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt b/templates/java/statics/android-uploader/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt index 42122c4c..b62cdc60 100644 --- a/templates/java/statics/android-uploader/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt +++ b/templates/java/statics/android-uploader/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt @@ -4,6 +4,8 @@ import android.content.pm.PackageManager import android.os.Build import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat class ReadStorePermissionManager( private val activity: ComponentActivity, @@ -18,20 +20,16 @@ class ReadStorePermissionManager( } private val hasPermission: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED - } else { - true - } + get() = ContextCompat.checkSelfPermission( + activity, + requiredPermission + ) == PackageManager.PERMISSION_GRANTED fun requestPermission() { if (hasPermission) { onGranted() } else { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw IllegalStateException("Permission should be granted") - } - if (activity.shouldShowRequestPermissionRationale(requiredPermission)) { + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, requiredPermission)) { onShowPermissionRationale(requiredPermission) { requestPermission.launch(requiredPermission) } diff --git a/templates/java/statics/android-uploader/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt b/templates/java/statics/android-uploader/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt index 6e34e760..b1a2a23e 100644 --- a/templates/java/statics/android-uploader/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt +++ b/templates/java/statics/android-uploader/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt @@ -4,6 +4,8 @@ import android.content.pm.PackageManager import android.os.Build import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat class ReadStorePermissionManager( private val activity: ComponentActivity, @@ -18,20 +20,16 @@ class ReadStorePermissionManager( } private val hasPermission: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED - } else { - true - } + get() = ContextCompat.checkSelfPermission( + activity, + requiredPermission + ) == PackageManager.PERMISSION_GRANTED fun requestPermission() { if (hasPermission) { onGranted() } else { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw IllegalStateException("Permission should be granted") - } - if (activity.shouldShowRequestPermissionRationale(requiredPermission)) { + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, requiredPermission)) { onShowPermissionRationale(requiredPermission) { requestPermission.launch(requiredPermission) } diff --git a/templates/java/statics/android/examples/service/src/main/java/video/api/client/service/example/ReadStorePermissionManager.kt b/templates/java/statics/android/examples/service/src/main/java/video/api/client/service/example/ReadStorePermissionManager.kt index 680eb8dc..8e9298c1 100644 --- a/templates/java/statics/android/examples/service/src/main/java/video/api/client/service/example/ReadStorePermissionManager.kt +++ b/templates/java/statics/android/examples/service/src/main/java/video/api/client/service/example/ReadStorePermissionManager.kt @@ -4,6 +4,8 @@ import android.content.pm.PackageManager import android.os.Build import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat class ReadStorePermissionManager( private val activity: ComponentActivity, @@ -18,20 +20,16 @@ class ReadStorePermissionManager( } private val hasPermission: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED - } else { - true - } + get() = ContextCompat.checkSelfPermission( + activity, + requiredPermission + ) == PackageManager.PERMISSION_GRANTED fun requestPermission() { if (hasPermission) { onGranted() } else { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw IllegalStateException("Permission should be granted") - } - if (activity.shouldShowRequestPermissionRationale(requiredPermission)) { + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, requiredPermission)) { onShowPermissionRationale(requiredPermission) { requestPermission.launch(requiredPermission) } diff --git a/templates/java/statics/android/examples/workmanager/src/main/java/video/api/client/work/example/ReadStorePermissionManager.kt b/templates/java/statics/android/examples/workmanager/src/main/java/video/api/client/work/example/ReadStorePermissionManager.kt index 92bae483..9df2f310 100644 --- a/templates/java/statics/android/examples/workmanager/src/main/java/video/api/client/work/example/ReadStorePermissionManager.kt +++ b/templates/java/statics/android/examples/workmanager/src/main/java/video/api/client/work/example/ReadStorePermissionManager.kt @@ -4,6 +4,8 @@ import android.content.pm.PackageManager import android.os.Build import androidx.activity.ComponentActivity import androidx.activity.result.contract.ActivityResultContracts +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat class ReadStorePermissionManager( private val activity: ComponentActivity, @@ -18,20 +20,16 @@ class ReadStorePermissionManager( } private val hasPermission: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - activity.checkSelfPermission(requiredPermission) == PackageManager.PERMISSION_GRANTED - } else { - true - } + get() = ContextCompat.checkSelfPermission( + activity, + requiredPermission + ) == PackageManager.PERMISSION_GRANTED fun requestPermission() { if (hasPermission) { onGranted() } else { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - throw IllegalStateException("Permission should be granted") - } - if (activity.shouldShowRequestPermissionRationale(requiredPermission)) { + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, requiredPermission)) { onShowPermissionRationale(requiredPermission) { requestPermission.launch(requiredPermission) }