https://kotlinlang.org logo
#android
Title
# android
j

jean

02/27/2023, 1:03 PM
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

Jonas de Faria Alves

02/27/2023, 1:52 PM
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

jean

02/28/2023, 9:22 AM
It worked, thanks!
👍 1
5 Views