Is there any way to ask permission programmatically in android ? I don't want to add all permission to AndroidManifest.xml. So is there any dialog that asks for permission at runtime?
-
3Why don't you want to use the manifest? The market place uses the manifest to make decisions about whether or not to make an app available to a given user per their hardware. If you don't list your requirements in the manifest, how would it know? – i_am_jorf Sep 22 '11 at 15:21
-
8@jeffamaphone For example if the feature requiring that permission isn't a core feature of my application. No need to bother every user with excessive permissions for features he doesn't use. You could even do that declaratively, by marking the permission as optional in the manifest. IMO the all-or-nothing mentality for permissions is one of the most annoying things about android. – CodesInChaos Nov 06 '11 at 15:11
-
3@CodeInChaos: Hmmm...I'm pretty sure I've seen apps dodge this by having smaller, separate "helper" applications that are invoked through intents. "Don't want to give our app too much power? Fine, install the base app. Want this extra feature? Fine, install this helper which has a broader permission set." – Piskvor left the building May 18 '12 at 11:34
-
1Just another remark: I've seen Android pop up a system dialog at app runtime telling me the app was trying to enable bluetooth and asking for my approval. So, at least in this case, Google seems to accept the 'risk' of prompting the user at runtime. – JimmyB Jul 23 '12 at 14:16
6 Answers
Applications statically declare the permissions they require, and the Android system prompts the user for consent at the time the application is installed. Android has no mechanism for granting permissions dynamically (at run-time) because it complicates the user experience to the detriment of security.

- 16,748
- 5
- 45
- 59
-
2I wonder how the time changes so quickly, it could complicate user experience in 2011 but not in 2015 ;) – Ankit Jun 26 '15 at 12:25
-
2
Not until now, but yes.
According to Google's new permission model introduced in Android M:
If an app running on the M Preview supports the new permissions model, the user does not have to grant any permissions when they install or upgrade the app. Instead, the app requests permissions as it needs them, and the system shows a dialog to the user asking for the permission.
Here's a summary of the key components of this new model:
Declaring Permissions: The app declares all the permissions it needs in the manifest, as in earlier Android platforms.
Permission Groups: Permissions are divided into permission groups, based on their functionality. For example, the
CONTACTS
permission group contains permissions to read and write the user's contacts and profile information.- Limited Permissions Granted at Install Time: When the user installs or updates the app, the system grants the app all permissions listed in the manifest that fall under
PROTECTION_NORMAL
. For example, alarm clock and internet permissions fall underPROTECTION_NORMAL
, so they are automatically granted at install time. For more information about how normal permissions are handled, see Normal Permissions. The system may also grant the app signature permissions, as described in System components and signature permissions. The user is not prompted to grant any permissions at install time. User Grants Permissions at Run-Time: When the app requests a permission, the system shows a dialog to the user, then calls the app's callback function to notify it whether the user granted the permission. This permission model changes the way your app behaves for features that require permissions. Here's a summary of the development practices you should follow to adjust to this model:
Always Check for Permissions: When the app needs to perform any action that requires a permission, it should first check whether it has that permission already. If it does not, it requests to be granted that permission. You do not need to check for permissions that fall under
PROTECTION_NORMAL
.Handle Lack of Permissions Gracefully: If the app is not granted an appropriate permission, it should handle the failure cleanly. For example, if the permission is just needed for an added feature, the app can disable that feature. If the permission is essential for the app to function, the app might disable all its functionality and inform the user that they need to grant that permission.
Permissions are Revocable: Users can revoke an app's permissions at any time. If a user turns off an app's permissions, the app is not notified. Once again, your app should verify that it has needed permissions before performing any restricted actions.
Source: https://developer.android.com/preview/features/runtime-permissions.html

- 14,105
- 13
- 56
- 97
No.
Answer here: get Android permission dynamiclly
See the "Uses Permissions" section here: http://developer.android.com/guide/topics/security/security.html
No. The user needs to be informed about the permissions while installing the application. Asking the user at runtime would be a security risk.

- 9,512
- 21
- 75
- 129

- 2,746
- 3
- 28
- 37
-
6"Asking them at runtime would be a security risk." How so? Only danger I see is clickjacking, and that can be easily prevented by a countdown. – CodesInChaos Nov 06 '11 at 15:09
-
3@CodeInChaos: "easily prevented"? You underestimate the power of "click through the big scary security warning to see funny video". – Piskvor left the building May 18 '12 at 11:31
-
25@Piskvor Those users will click through the warning at installation time as well. So I don't see how the risk is any larger than with install time warnings. – CodesInChaos May 18 '12 at 12:20
-
4I do not see the security risk at all. This is not different from validating it at install. It is the logic of Symbian and Blackberry10, which are clearly platforms with a better security – Benoit Jan 31 '14 at 17:51
-
Android M appears to have brought in some new permissions architecture to include permission dynamically. I have the same question now. – Saifur Rahman Mohsin Oct 14 '15 at 10:43
Android M introduced Runtime permissions, which everyone has been waiting for. Also the permissions are now categorized into NORMAL and DANGEROUS, where NORMAL permissions are granted by default and DANGEROUS permissions are requested when they are needed. Also DANGEROUS permissions can be revoked by the user at any time from the device's Settings menu.

- 61
- 8
If I combine the answers from 'Piskvor' and from 'Hanno Binder', your app can check if the helper app is available (try to invoke it with an Intent), and if it is not there (the invocation fails), prompt the user to install it.
Look at the following, for example.