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