android6-4 Exercise 2: The permission flow ======================================= import android.Manifest import android.os.Build import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.* @Composable fun NotificationPermissionButton(onResult: (Boolean) -> Unit) { val launcher = rememberLauncherForActivityResult( ActivityResultContracts.RequestPermission(), onResult // true if the user allowed it ) Button(onClick = { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { launcher.launch(Manifest.permission.POST_NOTIFICATIONS) } else { onResult(true) // before Android 13 there is nothing to ask } }) { Text("Allow reminders") } } import android.content.Intent import android.net.Uri import android.provider.Settings // Ask at the moment the user wants a reminder, not at app start. // If they said no, explain and offer the system settings page instead of asking again. fun openNotificationSettings(context: Context) { val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) .putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) context.startActivity(intent) } Flow: tap "Remind me" -> launcher asks -> onResult(true) schedules the reminder; onResult(false) shows a message "Reminders need notifications" with a button calling openNotificationSettings(context). Do not ask again on every tap. Report what the system does after two denials: general knowledge says it may stop showing the dialog (the launcher returns false straight away); confirm on your device and say which Android version. Code unrun.