Home | History | Annotate | Download | only in RuntimePermissions
      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-build"/>
     39 
     40     <metadata>
     41         <status>PUBLISHED</status>
     42         <categories>System</categories>
     43         <technologies>Android</technologies>
     44         <languages>Java</languages>
     45         <solutions>Mobile</solutions>
     46         <level>BEGINNER</level>
     47         <icon>screenshots/big_icon.png</icon>
     48         <screenshots>
     49             <img>screenshots/screenshot-1.png</img>
     50             <img>screenshots/screenshot-2.png</img>
     51         </screenshots>
     52         <api_refs>
     53             <android>android.app.Activity</android>
     54             <android>android.support.v4.app.ActivityCompat</android>
     55             <android>android.Manifest.permission</android>
     56         </api_refs>
     57 
     58         <description>
     59 <![CDATA[
     60 This sample shows runtime permissions available in Android M and above.
     61 It shows how to check and request permissions at runtime, handle backwards compatibility using the
     62 support library and how to declare optional permissions for M-devices only.
     63 ]]>
     64         </description>
     65 
     66         <intro>
     67 <![CDATA[
     68 Android M introduced runtime permissions. Applications targeting M and above need to request their
     69 permissions at runtime.
     70 All permissions still need to be declared in the AndroidManifest. However, when accessing APIs that
     71 require a permission, the Activity or Fragment has to verify that the permission has been granted
     72 or request the missing permissions using calls through the support library. Permissions are checked
     73 through  ActivityCompat#checkSelfPermission(Context, String) or
     74 ContextCompat#checkSelfPermission(Context, String).
     75 Permission are requested through ActivityCompat#requestPermissions(Activity, String[], int), and the response
     76 received in a callback to  ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[]).
     77 Applications can provide an additional rational for the use of permissions after calling
     78 ActivityCompat#shouldShowRequestPermissionRationale(Activity,String). This call will return true if the
     79 application should provide the user with more context on why the requested permissions is needed,
     80 for example if the permission request has been denied before.
     81 
     82 If an application targets an SDK below M, all permissions are granted at runtime and are available
     83 when the application is running. The support library calls handle these checks appropriately.
     84 However, if permissions have been turned off in the system settings
     85 for an application targeting an SDK below M, the API will return empty or no data.
     86 ]]>
     87         </intro>
     88     </metadata>
     89 </sample>
     90