I’m using this code for setting the brightness of ...
# android
j
I’m using this code for setting the brightness of the screen to max before showing a qr code :
Copy code
@Composable
fun BrightQrCode(
    saveCurrentBrightnessLevel: (Int) -> Unit,
    qrCode: @Composable () -> Unit,
) {
    val context: Context = LocalContext.current
    saveCurrentBrightnessLevel(Settings.System.getInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS))
    if (Settings.System.canWrite(context)) {
        Settings.System.putInt(context.contentResolver, Settings.System.SCREEN_BRIGHTNESS, 255)
    } else {
        LaunchedEffect(Unit) {
            val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.data = Uri.parse("package:" + context.activity?.packageName);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(context, intent, null)
        }
    }

    qrCode()
}
The problem is that it’s not recomposing when navigating back after giving the permission to my app. How can I fix that?
j
You probably need a
DisposableEffect
:
A side effect of composition that must run for any new unique value of [key1] and must be reversed or cleaned up if [key1] changes or if the [DisposableEffect] leaves the composition.
j
It worked, thanks!
👍 1