README.md
1Android AppRestrictionSchema Sample
2===================================
3
4A basic app showing how to allow a device administrator to restrict user
5activities using the Android Device Administration API. The app exports
6a custom policy that enables or disables a UI control. Device Administration
7applications are able to enforce a specific value for this policy, as
8directed by enterprise administrators.
9
10Introduction
11------------
12
13The [Android Device Administration API][1] allows enterprise administrators to
14enforce specific policies on a managed device. The system provides policies
15that control settings such as password complexity, screen lock, or camera
16availability. Developers can also augment this list with custom policies
17that control specific features within their applications. For example,
18a web browser could provide access to a whitelist of allowed domains.
19
20The list of policies exposed by an app must be specified using a file
21inside of the `res/xml` directory, using the `<restriction>` tag:
22
23```xml
24<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
25
26 <restriction
27 android:defaultValue="false"
28 android:description="@string/description_can_say_hello"
29 android:key="can_say_hello"
30 android:restrictionType="bool"
31 android:title="@string/title_can_say_hello" />
32
33</restrictions>
34```
35
36In this sample, that file can be found at
37`Application/src/main/res/xml/app_restrictions.xml`. This file must be
38also be declared inside of `ApplicationManifest.xml` using a `<meta-data>`
39element:
40
41```xml
42<meta-data
43 android:name="android.content.APP_RESTRICTIONS"
44 android:resource="@xml/app_restrictions" />
45```
46
47At runtime, the current list of restrictions enforced by policy can be
48checked by calling [RestrictionsManager.getApplicationRestrictions()][2].
49
50[1]: http://developer.android.com/guide/topics/admin/device-admin.html
51[2]: https://developer.android.com/reference/android/content/RestrictionsManager.html#getApplicationRestrictions()
52
53Pre-requisites
54--------------
55
56- Android SDK v21
57- Android Build Tools v21.1.1
58- Android Support Repository
59
60Screenshots
61-------------
62
63<img src="screenshots/main.png" height="400" alt="Screenshot"/>
64
65Getting Started
66---------------
67
68This sample uses the Gradle build system. To build this project, use the
69"gradlew build" command or use "Import Project" in Android Studio.
70
71Support
72-------
73
74- Google+ Community: https://plus.google.com/communities/105153134372062985968
75- Stack Overflow: http://stackoverflow.com/questions/tagged/android
76
77If you've found an error in this sample, please file an issue:
78https://github.com/googlesamples/android-AppRestrictionSchema
79
80Patches are encouraged, and may be submitted by forking this project and
81submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
82
83License
84-------
85
86Copyright 2014 The Android Open Source Project, Inc.
87
88Licensed to the Apache Software Foundation (ASF) under one or more contributor
89license agreements. See the NOTICE file distributed with this work for
90additional information regarding copyright ownership. The ASF licenses this
91file to you under the Apache License, Version 2.0 (the "License"); you may not
92use this file except in compliance with the License. You may obtain a copy of
93the License at
94
95http://www.apache.org/licenses/LICENSE-2.0
96
97Unless required by applicable law or agreed to in writing, software
98distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
99WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
100License for the specific language governing permissions and limitations under
101the License.
102