1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2015 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<sample>
18    <name>RuntimePermissions</name>
19    <group>System</group>
20    <package>com.example.android.system.runtimepermissions</package>
21
22    <minSdk>15</minSdk>
23
24    <dependency>com.android.support:support-v4:24.0.0</dependency>
25    <dependency>com.android.support:design:24.0.0</dependency>
26
27    <strings>
28        <intro>
29            <![CDATA[
30            This sample shows runtime permissions available in Android M and above.
31            Display the log on screen to follow the execution.
32            If executed on an Android M device, an additional option to access contacts is shown
33            that is declared with optional, M and above only permissions.
34            ]]>
35        </intro>
36    </strings>
37
38    <template src="base"/>
39    <common src="logger"/>
40
41    <metadata>
42        <status>DRAFT</status>
43        <categories>System</categories>
44        <technologies>Android</technologies>
45        <languages>Java</languages>
46        <solutions>Mobile</solutions>
47        <level>BEGINNER</level>
48        <icon>screenshots/big_icon.png</icon>
49        <screenshots>
50            <img>screenshots/screenshot-1.png</img>
51            <img>screenshots/screenshot-2.png</img>
52        </screenshots>
53        <api_refs>
54            <android>android.app.Activity</android>
55            <android>android.support.v4.app.ActivityCompat</android>
56            <android>android.Manifest.permission</android>
57        </api_refs>
58
59        <description>
60<![CDATA[
61This sample shows runtime permissions available in Android M and above.
62It shows how to check and request permissions at runtime, handle backwards compatibility using the
63support library and how to declare optional permissions for M-devices only.
64]]>
65        </description>
66
67        <intro>
68<![CDATA[
69Android M introduced runtime permissions. Applications targeting M and above need to request their
70permissions at runtime.
71All permissions still need to be declared in the AndroidManifest. However, when accessing APIs that
72require a permission, the Activity or Fragment has to verify that the permission has been granted
73or request the missing permissions using calls through the support library. Permissions are checked
74through  ActivityCompat#checkSelfPermission(Context, String) or
75ContextCompat#checkSelfPermission(Context, String).
76Permission are requested through ActivityCompat#requestPermissions(Activity, String[], int), and the response
77received in a callback to  ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[]).
78Applications can provide an additional rational for the use of permissions after calling
79ActivityCompat#shouldShowRequestPermissionRationale(Activity,String). This call will return true if the
80application should provide the user with more context on why the requested permissions is needed,
81for example if the permission request has been denied before.
82
83If an application targets an SDK below M, all permissions are granted at runtime and are available
84when the application is running. The support library calls handle these checks appropriately.
85However, if permissions have been turned off in the system settings
86for an application targeting an SDK below M, the API will return empty or no data.
87]]>
88        </intro>
89    </metadata>
90</sample>
91