User does not has 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.
Overview
With the M Developer Preview, the platform introduces a new app permissions model. Here's a summary of the key components of this new model:
- declaring Permissions: The app declares all of the permissions it needs in the manifest and as in earlier Android platforms.
- Permission Groups: permissions is 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 Under   PROTECTION _normal , so they is automatically granted at install time. For more information on how normal permissions is handled, See normal Permissions.
The system may also grant the app signature permissions, as described In syst EM components and signature permissions. The user Is  not Prompted to grant no permissions at install time.
- User Grants Permissions at Run-time: When the app is requests a permission, the system shows a dialog to the user and then calls the app's callback function to Notify it whether the user granted the permission.
This permission model changes the 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 nee DS to perform any action requires a permission, it should first check whether it have that permission already. If it does not, it requests to be granted that permission. You don't 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 are just needed for a 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 th At they need to grant that permission.
Figure 1. Permission in the app ' s Settings.
- Permissions is revocable: Users can revoke an app's permissions at any time. If a user turns off an app ' s permissions, the app isn't notified. Once again, your app should verify that it had needed permissions before performing any restricted actions.
Note: If The app targets the M Developer Preview, it must use the new permissions model.
As of the launch of the M Developer Preview, not all Google apps fully implement the new permissions model. Google is updating these apps over the course of the M Developer Preview to properly respect Permissions toggle settings.
Note: If Your app has it own API surface, do not proxy permissions without first ensuring the caller have the requisite per Missions to access that data.
Permission groups
Related permissions is divided into permission groups to allow users to grant related permissions to an App in a single action. The user has a to grant permission once per app for each permission group. If The app subsequently requests a permission from the same permission group, the system automatically grants the Permissi On without any action from the user. The system calls your app ' s onRequestPermissionsResult() method Just as if the user had granted permission through the dialog box.
For example, suppose a app lists in its manifest that it needs the&NBSP; send_sms and< Span class= "Apple-converted-space" >&NBSP; receive_sms permissions, which both belong To&NBSP; android.permission-group.sms . When the app needs to send a message, it requests the send_sms Permission. The system shows the User a dialog box asking if the app can have access to SMS. If the user agrees, the system grants the app The&NBSP; send_sms permission it requested. Later, the app requests receive_sms . The system automatically grants this permission, since the user had already approved a permission in the same permission G Roup.
System Components and Signature permissions
Ordinarily, when the user installs an app, the system is grants the app the permissions listed in the manifest that fall Under PROTECTION_NORMAL . However, under some circumstances the system grants the app more permissions:
- System components automatically receive all the permissions listed in their manifests.
- If the app requests permissions in the manifest that fall under
PROTECTION_SIGNATURE , and the app are signed with the same certificate As the app, declared those permissions, the system grants the requesting app those permissions on installation. Apps cannot request signature permissions at runtime.
Forwards and backwards compatibility
If The app does not target the M Developer preview, the app continues to use the old permissions model even on M preview de Vices. When the user installs the app, the system asks the user-grant all permissions listed in the app ' s manifest.
Note: On devices running the M Developer Preview, a user can turn off permissions for all app (including legacy apps) from The app ' s Settings screen. If A user turns off permissions for a legacy app, the system silently disables the appropriate functionality. When the app is attempts to perform a operation that requires that permission, the operation won't necessarily cause an E Xception. Instead, it might return an empty data set, signal an error, or otherwise exhibit unexpected. For example, if you query a calendar without permission, the method returns an empty data set.
If you install the "an" app using the new permissions model on a device which is not running the M Preview, the system treats it The same as any and app:the system asks the user to grant all declared permissions at install time.
Note: for the "preview release, you must set" the minimum SDK version to the "M" Preview SDK to compile with the Preview SDK. T His means is not being able to test such apps on older platforms during the developer preview.
Permissions versus intents
In the many cases, you can choose between the ways for your app to perform a task. You can has your app ask for permission to perform the operation itself. Alternatively, you can have the app with the intent to the another app perform the task.
For example, suppose your apps needs to is able to take pictures with the device camera. Your app can request The&NBSP; Android.permission.CAMERA permission, which allows your app to access the camera directly. Your app would then use the camera APIs to control the camera and take a picture. This approach gives your app full control over the photography process, and lets your incorporate the camera UI into your a pp.
However, if you don ' t need the such control, you can just the use of an intent to the ACTION_IMAGE_CAPTURE request an image. When you start the intent, the user was prompted to choose a camera app (if there isn ' t already a default camera app), and That app takes the picture. The camera app returns the picture to your app ' s onActivityResult() method.
Similarly, if you need to make a phone call, access the user's contacts, and so on, you can do it by creating an APPROPR Iate intent, or you can request the permission and access the appropriate objects directly. There is advantages and disadvantages to each approach.
If You use permissions:
- The Your app has full control over the user experience if you perform the operation. However, such broad control adds to the complexity of your task, since your need to design an appropriate UI.
- The user is prompted to give permission once and the first time you perform the operation. After this, the your app can perform the operation without requiring additional interaction from the user. However, if the user doesn ' t grant the permission (or revokes it later on), your apps becomes unable to perform the Operati On @ all.
If you use an intent:
- You don't have a to design the UI for the operation. The app that handles the intent provides the UI. However, this means you has no control over the user experience. The user could is interacting with a app you ' ve never seen.
- If the user does not has a default app for the operation, the system prompts the user to choose an app. If the user does not designate a default handler, they may has to go through an extra dialog every time they perform the Operation.
Coding for Runtime Permissions
If your app targets the new M Developer Preview, you must use the new permissions model. This means is addition to declaring your needed permissions in the manifest, you must also check to see if you have t He permissions at run time, and request the permissions if your do not already has them.
Enabling the new Permissions model
To enable the new M Developer Preview permissions model, set the app's targetSdkVersion attribute "MNC" to, and compileSdkVersion to "android-MNC" . Doing so enables all the new permissions features.
For the preview release, you must set to compile with the minSdkVersion "MNC" preview SDK.
Designating a permission for the M Preview only
You can use the New&NBSP; <uses-permission-sdk-m> element in the app manifest to indicate that a permission are only needed on the M deve Loper Preview. If you declare a permission this to, then whenever the app was installed on an older device, the system does not prompt th e user or grant the permission to the app. By using The&NBSP; <uses-permission-sdk-m> element, you can add new permissions to updated versions of your apps without forcing users to Grant permissions when they install the update.
If The app is running on a device with the M Developer Preview, <uses-permission-sdk-m> behaves the same as <uses-permission> . The system does not prompt the user to grant any permissions when they install the app, and the app requests permissions A s they is needed.
Prompting for permissions
If your app uses the new M Developer Preview permissions model, the user is not asked to grant all permissions when the AP P is first launched on a device running the M Preview. Instead, your app requests permissions as they is needed. When your apps requests a permission, the system shows a dialog to the user.
If your app runs on a device it has SDK at or lower, the app uses the old permissions model. When the user installs the app, they is prompted to grant all the permissions your apps requests in its manifest, except F Or those permissions which is labeled with <uses-permission-sdk-m> .
Check what platform the app was running on
This permissions model was only supported on devices running the M Developer Preview. Before calling any of these methods, the app should verify what platform it's running on by checking the value of . If the device is running the M Developer Preview, is CODENAME "MNC" .
Check If the app has the needed permission
When the user tries to does something that requires a permission and the app checks to see if it currently have permission to PE Rform this operation. To does this, the app calls Context.checkSelfPermission(permission_name) . The app should perform this check even if it knows the user have already granted that permission, since the user can revoke An app's permissions at any time. For example, if a user wants to use an app to take a picture, the app calls Context.checkSelfPermission(Manifest.permission.CAMERA) .
Permissions new features of Android m