Bird
Raised Fist0
Android Kotlinmobile~10 mins

Why runtime permissions protect user privacy in Android Kotlin - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to request a runtime permission for accessing the camera.

Android Kotlin
ActivityCompat.requestPermissions(this, arrayOf([1]), 100)
Drag options to blanks, or click blank then click option'
AManifest.permission.CAMERA
BManifest.permission.ACCESS_FINE_LOCATION
CManifest.permission.READ_CONTACTS
DManifest.permission.RECORD_AUDIO
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a permission unrelated to the camera like location or contacts.
Forgetting to use the full permission string.
2fill in blank
medium

Complete the code to check if the app already has permission to read contacts.

Android Kotlin
if (ContextCompat.checkSelfPermission(this, [1]) == PackageManager.PERMISSION_GRANTED) {
    // Permission granted
}
Drag options to blanks, or click blank then click option'
AManifest.permission.READ_CONTACTS
BManifest.permission.ACCESS_FINE_LOCATION
CManifest.permission.CAMERA
DManifest.permission.RECORD_AUDIO
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for a different permission than intended.
Using incorrect permission string format.
3fill in blank
hard

Fix the error in the code to handle the user's response to a permission request.

Android Kotlin
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, [1]: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if (requestCode == 100 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        // Permission granted
    }
}
Drag options to blanks, or click blank then click option'
ApermissionResults
Bresults
CgrantResults
DpermissionsResults
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name causes a compilation error.
Not matching the method signature exactly.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps permissions to their grant status.

Android Kotlin
val permissionStatus = permissions.associateWith { [1][permissions.indexOf(it)] == [2] }
Drag options to blanks, or click blank then click option'
AgrantResults
BPackageManager.PERMISSION_GRANTED
CPackageManager.PERMISSION_DENIED
DrequestCode
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong constant for permission status.
Confusing the array holding results with other variables.
5fill in blank
hard

Fill all three blanks to request multiple permissions and handle the result.

Android Kotlin
ActivityCompat.requestPermissions(this, arrayOf([1], [2]), [3])

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
    if (requestCode == [3]) {
        for (i in permissions.indices) {
            if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                // Permission [1] or [2] granted
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
AManifest.permission.CAMERA
BManifest.permission.ACCESS_FINE_LOCATION
C101
D102
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched request codes in request and result handling.
Requesting permissions not declared in the manifest.

Practice

(1/5)
1. Why do Android apps request runtime permissions instead of asking for all permissions at install time?
easy
A. To protect user privacy by asking only when the permission is needed
B. To make the app install faster
C. To reduce the app size
D. To avoid asking the user any questions

Solution

  1. Step 1: Understand runtime permissions purpose

    Runtime permissions ask users only when a feature needs access, protecting privacy.
  2. Step 2: Compare with install-time permissions

    Install-time permissions ask all at once, which can overwhelm users and reduce control.
  3. Final Answer:

    To protect user privacy by asking only when the permission is needed -> Option A
  4. Quick Check:

    Runtime permissions = protect privacy [OK]
Hint: Runtime permissions ask only when needed, protecting privacy [OK]
Common Mistakes:
  • Thinking runtime permissions speed up installation
  • Believing runtime permissions reduce app size
  • Assuming runtime permissions avoid user prompts
2. Which Kotlin code snippet correctly checks if the app has permission to access the camera before requesting it?
easy
A. if (checkPermission(Manifest.permission.CAMERA)) { /* permission granted */ }
B. if (hasPermission(Manifest.permission.CAMERA)) { /* permission granted */ }
C. if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { /* permission granted */ }
D. if (requestPermission(Manifest.permission.CAMERA)) { /* permission granted */ }

Solution

  1. Step 1: Identify correct permission check method

    ContextCompat.checkSelfPermission returns permission status in Android Kotlin.
  2. Step 2: Verify correct comparison

    Compare result to PackageManager.PERMISSION_GRANTED to confirm permission granted.
  3. Final Answer:

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { /* permission granted */ } -> Option C
  4. Quick Check:

    Use ContextCompat.checkSelfPermission == PERMISSION_GRANTED [OK]
Hint: Use ContextCompat.checkSelfPermission with PERMISSION_GRANTED check [OK]
Common Mistakes:
  • Using non-existent methods like checkPermission or hasPermission
  • Calling requestPermission instead of checking permission
  • Not comparing to PERMISSION_GRANTED constant
3. Given this Kotlin code snippet, what will be the output if the user denies the permission request?
if (ContextCompat.checkSelfPermission(this, Manifest.permission.LOCATION) != PackageManager.PERMISSION_GRANTED) {
  ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.LOCATION), 100)
} else {
  println("Permission already granted")
}
medium
A. Nothing printed immediately; permission request dialog shown
B. Permission already granted
C. App crashes due to missing permission
D. Permission denied message printed

Solution

  1. Step 1: Analyze permission check condition

    Permission is not granted, so requestPermissions is called to ask user.
  2. Step 2: Understand immediate output

    requestPermissions shows dialog asynchronously; no immediate print happens.
  3. Final Answer:

    Nothing printed immediately; permission request dialog shown -> Option A
  4. Quick Check:

    Permission request dialog shows, no immediate print [OK]
Hint: requestPermissions shows dialog, no immediate output printed [OK]
Common Mistakes:
  • Assuming println runs before user responds
  • Expecting crash without handling permission denial
  • Thinking denial message prints automatically
4. What is wrong with this Kotlin code snippet for requesting permission?
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS), 1)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
  println("Permission granted")
}
medium
A. println statement should be outside the if block
B. Permission check is done immediately after request, before user responds
C. Manifest.permission.READ_CONTACTS is not a valid permission
D. requestPermissions method is called with wrong parameters

Solution

  1. Step 1: Understand requestPermissions behavior

    requestPermissions shows dialog asynchronously; user response is not immediate.
  2. Step 2: Identify timing of permission check

    Checking permission immediately after request will not reflect user's choice yet.
  3. Final Answer:

    Permission check is done immediately after request, before user responds -> Option B
  4. Quick Check:

    Check permission after user response, not immediately [OK]
Hint: Check permission after user responds, not right after request [OK]
Common Mistakes:
  • Checking permission immediately after requestPermissions call
  • Assuming requestPermissions blocks until user answers
  • Misusing permission constants
5. An app needs to access the user's location only when showing nearby stores. How should it use runtime permissions to protect user privacy best?
hard
A. Request all permissions including location at install time
B. Request location permission immediately when the app starts
C. Never request location permission and guess location from IP
D. Request location permission only when the user tries to view nearby stores

Solution

  1. Step 1: Identify when location is needed

    Location is needed only when user views nearby stores, not before.
  2. Step 2: Apply runtime permission best practice

    Request permission only at the moment feature is used to respect privacy and reduce prompts.
  3. Final Answer:

    Request location permission only when the user tries to view nearby stores -> Option D
  4. Quick Check:

    Request permission when feature used, protect privacy [OK]
Hint: Ask permission only when feature needs it, not before [OK]
Common Mistakes:
  • Requesting permission too early at app start
  • Requesting all permissions upfront at install
  • Avoiding permission request and guessing location
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard