diff --git a/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt b/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt index 42122c4..b62cdc6 100644 --- a/examples/service/src/main/java/video/api/uploader/service/example/ReadStorePermissionManager.kt +++ b/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/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt b/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt index 6e34e76..b1a2a23 100644 --- a/examples/workmanager/src/main/java/video/api/uploader/work/example/ReadStorePermissionManager.kt +++ b/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) }