This is my code to fetch read permission for galle...
# compose
k
This is my code to fetch read permission for gallery, and it is working fine on every Android version, except Android 12. On android 12, launcher's result call back is invoked with 'false' value when launcher is initiated first time, and permission dialogs pops up, but the very same call back isn't triggered when user allows the permission. Hence, it needs to recreate the launcher object to get the updated value. And it only happens on android 12... checked on both real device and emulator and result is same.
Copy code
@Composable
actual fun FetchGalleryReadPermission(state: (Boolean) -> Unit) {
    val permission = remember {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
            Manifest.permission.READ_EXTERNAL_STORAGE
        } else {
            Manifest.permission.READ_MEDIA_IMAGES
        }
    }

    val context = LocalContext.current

    val permissionState by remember {
        mutableStateOf(
            ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
        )
    }

    val launcher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.RequestPermission()
    ) { isGranted ->
        state(isGranted)
    }

    LaunchedEffect(permissionState) {
        if (!permissionState) {
            launcher.launch(permission)
        } else {
            state(true)
        }
    }
}
🙌 1
🧵 1
y
use calf permission
k
Thanks for the suggestion... But I have it fixed already...