What method do you use to check if a permission is already granted?
Use ContextCompat.checkSelfPermission(context, permission) which returns PackageManager.PERMISSION_GRANTED or PackageManager.PERMISSION_DENIED.
Click to reveal answer
beginner
How do you request permissions from the user in an Activity?
Call ActivityCompat.requestPermissions(activity, arrayOf(permission), requestCode) to show the permission dialog.
Click to reveal answer
beginner
What callback handles the user's response to a permission request?
The onRequestPermissionsResult(requestCode, permissions, grantResults) callback receives the user's decision.
Click to reveal answer
At what point should you request a dangerous permission in Android?
AWhen the app is installed
BNever
CBefore the app launches
DWhen the user tries to use a feature that needs the permission
✗ Incorrect
Request permissions only when the user tries to use a feature that requires it, to respect user privacy.
Which method checks if a permission is granted?
AcheckPermissionGranted()
BrequestPermissions()
CContextCompat.checkSelfPermission()
DonRequestPermissionsResult()
✗ Incorrect
ContextCompat.checkSelfPermission() returns whether the permission is granted or denied.
What does ActivityCompat.requestPermissions() do?
AShows a dialog to ask the user for permission
BChecks if permission is granted
CRevokes a permission
DStarts a new activity
✗ Incorrect
It shows the system dialog asking the user to grant or deny the requested permissions.
Which callback receives the user's permission decision?
AonRequestPermissionsResult()
BonPermissionResult()
ConPermissionGranted()
DonUserResponse()
✗ Incorrect
onRequestPermissionsResult() is called with the user's response to the permission request.
If a user denies a permission, what should your app do?
ACrash immediately
BExplain why the permission is needed and offer to request again
CKeep requesting permission repeatedly without explanation
DIgnore the permission and continue as if granted
✗ Incorrect
You should politely explain why the permission is needed and ask again if appropriate.
Describe the steps to request a dangerous permission at runtime in an Android app.
Think about checking first, then asking, then reacting.
You got /3 concepts.
Explain why Android requires runtime permission requests instead of asking all permissions at install time.
Consider how users feel about privacy and control.
You got /3 concepts.
Practice
(1/5)
1. What is the first step before requesting a dangerous permission in Android Kotlin?
easy
A. Restart the app
B. Directly call requestPermissions without checking
C. Show a Toast message to the user
D. Check if the permission is already granted
Solution
Step 1: Understand permission checking
Before asking for permission, the app must check if it already has it to avoid unnecessary requests.
Step 2: Use ContextCompat.checkSelfPermission
This method returns if the permission is granted or denied, guiding the next action.
Final Answer:
Check if the permission is already granted -> Option D
Quick Check:
Check permission first = A [OK]
Hint: Always check permission status before requesting [OK]
Common Mistakes:
Requesting permission without checking first
Assuming permission is granted by default
Ignoring permission status before action
2. Which Kotlin code snippet correctly requests a permission from an Activity?
easy
A. ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 100)
B. requestPermissions(Manifest.permission.CAMERA, 100)
C. Activity.requestPermissions(this, Manifest.permission.CAMERA, 100)
D. requestPermission(Manifest.permission.CAMERA)
Solution
Step 1: Identify correct method signature
ActivityCompat.requestPermissions requires context, array of permissions, and request code.
Step 2: Check syntax correctness
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 100) matches the correct syntax with 'this' as context and arrayOf for permissions.
Final Answer:
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 100) -> Option A
Quick Check:
Correct requestPermissions syntax = D [OK]
Hint: Use ActivityCompat.requestPermissions with arrayOf permissions [OK]