0
0
Android Kotlinmobile~10 mins

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

Choose your learning style9 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.