1
2Android RuntimePermissions Sample
3===================================
4
5This sample shows runtime permissions available in Android M and above.
6It shows how to check and request permissions at runtime, handle backwards compatibility using the
7support library and how to declare optional permissions for M-devices only.
8
9Introduction
10------------
11
12Android M introduced runtime permissions. Applications targeting M and above need to request their
13permissions at runtime.
14All permissions still need to be declared in the AndroidManifest. However, when accessing APIs that
15require a permission, the Activity or Fragment has to verify that the permission has been granted
16or request the missing permissions using calls through the support library. Permissions are checked
17through  ActivityCompat#checkSelfPermission(Context, String) or
18ContextCompat#checkSelfPermission(Context, String).
19Permission are requested through ActivityCompat#requestPermissions(Activity, String[], int), and the response
20received in a callback to  ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[]).
21Applications can provide an additional rational for the use of permissions after calling
22ActivityCompat#shouldShowRequestPermissionRationale(Activity,String). This call will return true if the
23application should provide the user with more context on why the requested permissions is needed,
24for example if the permission request has been denied before.
25
26If an application targets an SDK below M, all permissions are granted at runtime and are available
27when the application is running. The support library calls handle these checks appropriately.
28However, if permissions have been turned off in the system settings
29for an application targeting an SDK below M, the API will return empty or no data.
30
31Pre-requisites
32--------------
33
34- Android SDK 27
35- Android Build Tools v27.0.2
36- Android Support Repository
37
38Screenshots
39-------------
40
41<img src="screenshots/screenshot-1.png" height="400" alt="Screenshot"/> <img src="screenshots/screenshot-2.png" height="400" alt="Screenshot"/>
42
43Getting Started
44---------------
45
46This sample uses the Gradle build system. To build this project, use the
47"gradlew build" command or use "Import Project" in Android Studio.
48
49Support
50-------
51
52- Google+ Community: https://plus.google.com/communities/105153134372062985968
53- Stack Overflow: http://stackoverflow.com/questions/tagged/android
54
55If you've found an error in this sample, please file an issue:
56https://github.com/googlesamples/android-RuntimePermissions
57
58Patches are encouraged, and may be submitted by forking this project and
59submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
60
61License
62-------
63
64Copyright 2017 The Android Open Source Project, Inc.
65
66Licensed to the Apache Software Foundation (ASF) under one or more contributor
67license agreements.  See the NOTICE file distributed with this work for
68additional information regarding copyright ownership.  The ASF licenses this
69file to you under the Apache License, Version 2.0 (the "License"); you may not
70use this file except in compliance with the License.  You may obtain a copy of
71the License at
72
73http://www.apache.org/licenses/LICENSE-2.0
74
75Unless required by applicable law or agreed to in writing, software
76distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
77WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
78License for the specific language governing permissions and limitations under
79the License.
80