Simone Aonzo
Simone Aonzo

Reputation: 921

Borderline cases when requesting Android permissions at runtime

On Android >= 6:

  1. When a method, that requires a permission P, is invoked but the permission P isn't declared in the manifest a java.lang.SecurityException will be raised.

  2. The same exception occurs when I doesn't check if a dangerous permission was granted and I invoke a method that uses it.

  3. When you ask for a dangerous permission P at runtime with the ActivityCompat.requestPermissions method, but the dangerous permission P isn't declared in the manifest, the dialog box doesn't appear and the permission is denied by default (and you can't see that this happened looking the logs).

Are those claims right?

Upvotes: 0

Views: 43

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006724

When a method, that requires a permission P, is invoked but the permission P isn't declared in the manifest a java.lang.SecurityException will be raised.

Correct in general. There may be some fringe cases where some other exception gets raised. The behavior secured by the permission will not work normally.

The same exception occurs when I doesn't check if a dangerous permission was granted and I invoke a method that uses it.

Only on Android 6.0+, for apps with targetSdkVersion 23 or higher.

When you ask for a dangerous permission P at runtime with the ActivityCompat.requestPermissions method, but the dangerous permission P isn't declared in the manifest, the dialog box doesn't appear and the permission is denied by default (and you can't see that this happened looking the logs).

The "denied by default" part is identical to your first question. Otherwise, you are correct — you can only request runtime permissions for those dangerous ones that you requested in the manifest.

Upvotes: 1

Related Questions