0
0
Android Kotlinmobile~20 mins

Why runtime permissions protect user privacy in Android Kotlin - Build It to Prove It

Choose your learning style9 modes available
Build: Runtime Permissions Explanation
This screen explains why runtime permissions are important to protect user privacy in Android apps.
Target UI
----------------------------------
| Runtime Permissions Explanation |
----------------------------------
| Why runtime permissions matter: |
|                                |
| 1. User control: Apps ask for  |
|    permission when needed.     |
| 2. Transparency: Users see     |
|    what data apps want.        |
| 3. Privacy: Apps can't access   |
|    sensitive info without      |
|    permission.                 |
|                                |
| [OK]                          |
----------------------------------
Display a title at the top
Show a list of three simple reasons why runtime permissions protect privacy
Add an OK button at the bottom that closes the screen
Use clear and friendly language
Starter Code
Android Kotlin
package com.example.runtimepermissions

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      RuntimePermissionsScreen(onOkClicked = { finish() })
    }
  }
}

@Composable
fun RuntimePermissionsScreen(onOkClicked: () -> Unit) {
  // TODO: Add UI here
}
Task 1
Task 2
Task 3
Task 4
Solution
Android Kotlin
package com.example.runtimepermissions

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      RuntimePermissionsScreen(onOkClicked = { finish() })
    }
  }
}

@Composable
fun RuntimePermissionsScreen(onOkClicked: () -> Unit) {
  Column(
    modifier = Modifier
      .fillMaxSize()
      .padding(16.dp),
    verticalArrangement = Arrangement.SpaceBetween
  ) {
    Column {
      Text(
        text = "Runtime Permissions Explanation",
        fontSize = 24.sp,
        fontWeight = FontWeight.Bold,
        modifier = Modifier.padding(bottom = 24.dp)
      )
      Text(text = "1. User control: Apps ask for permission when needed.", fontSize = 18.sp, modifier = Modifier.padding(bottom = 12.dp))
      Text(text = "2. Transparency: Users see what data apps want.", fontSize = 18.sp, modifier = Modifier.padding(bottom = 12.dp))
      Text(text = "3. Privacy: Apps can't access sensitive info without permission.", fontSize = 18.sp)
    }
    Button(
      onClick = onOkClicked,
      modifier = Modifier
        .fillMaxWidth()
        .height(48.dp)
    ) {
      Text(text = "OK")
    }
  }
}

This screen uses a vertical column layout with padding for spacing. The title is bold and larger to stand out. Below it, three simple sentences explain why runtime permissions protect privacy, using friendly and clear language. The OK button at the bottom closes the screen when tapped, giving a natural way to exit.

This approach helps users understand the importance of permissions in a calm and simple way, respecting their control and privacy.

Final Result
Completed Screen
----------------------------------
| Runtime Permissions Explanation |
----------------------------------
| 1. User control: Apps ask for   |
|    permission when needed.      |
| 2. Transparency: Users see      |
|    what data apps want.         |
| 3. Privacy: Apps can't access   |
|    sensitive info without       |
|    permission.                 |
|                                |
| [           OK           ]      |
----------------------------------
User reads the three reasons why runtime permissions protect privacy
User taps the OK button to close the screen
Stretch Goal
Add a dark mode toggle switch that changes the screen colors between light and dark themes.
💡 Hint
Use Compose's MaterialTheme with light and dark color schemes and a Switch composable to toggle state.