• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

.google/22-Nov-2023-1914

Application/22-Nov-2023-2,2071,055

gradle/wrapper/22-Nov-2023-76

screenshots/22-Nov-2023-

CONTRIBUTING.mdD22-Nov-20231.5 KiB3627

LICENSED22-Nov-202311.1 KiB202169

NOTICED22-Nov-2023613 1611

README.mdD22-Nov-20233.5 KiB9469

build.gradleD22-Nov-202311 120

gradlewD22-Nov-20235 KiB165122

gradlew.batD22-Nov-20232.3 KiB9166

settings.gradleD22-Nov-202322 21

README.md

1Android PermissionRequest Sample
2===================================
3
4This sample demonstrates how to use the PermissionRequest API to
5securely provide access to restricted system features (such as a
6camera or microphone) from within a WebView. In this example, a dialog
7is created to allow users to explicitly approve or reject each
8request.
9
10Introduction
11------------
12
13PermissionRequest can be used by setting up a custom WebChromeClient.
14
15```java
16mWebView.setWebChromeClient(mWebChromeClient);
17```
18
19In you WebChromeClient implementation, you need to override
20[onPermissionRequest][1]. This method is called when the web content
21is requesting permission to access some resources, providing an
22opportunity to approve or reject the request. In this implementation,
23we display a dialog to allow the user to approve or reject any
24request. In other applications, you may want to implement a whitelist
25of allowed APIs.  Also, override [onPermissionRequestCanceled][2] for
26handling cancellation of the PermissionRequest by the web content.
27
28When the user confirms or denies the request, you can respond back to
29the web content by [grant][3] or [deny][4] respectively.
30
31```java
32mPermissionRequest.grant(mPermissionRequest.getResources());
33```
34
35This sample provides the web content from the assets folder in the
36app. Since WebView is not allowed to use getUserMedia from a "file://"
37URL, the app uses the SimpleWebServer class to provide the content via
38"http://localhost".
39
40[1]: http://developer.android.com/reference/android/webkit/WebChromeClient.html#onPermissionRequest(android.webkit.PermissionRequest)
41[2]: http://developer.android.com/reference/android/webkit/WebChromeClient.html#onPermissionRequestCanceled(android.webkit.PermissionRequest)
42[3]: http://developer.android.com/reference/android/webkit/PermissionRequest.html#grant(java.lang.String[])
43[4]: http://developer.android.com/reference/android/webkit/PermissionRequest.html#deny()
44
45Pre-requisites
46--------------
47
48- Android SDK v21
49- Android Build Tools v21.1.1
50- Android Support Repository
51
52Screenshots
53-------------
54
55<img src="screenshots/main.png" height="400" alt="Screenshot"/>
56
57Getting Started
58---------------
59
60This sample uses the Gradle build system. To build this project, use the
61"gradlew build" command or use "Import Project" in Android Studio.
62
63Support
64-------
65
66- Google+ Community: https://plus.google.com/communities/105153134372062985968
67- Stack Overflow: http://stackoverflow.com/questions/tagged/android
68
69If you've found an error in this sample, please file an issue:
70https://github.com/googlesamples/android-PermissionRequest
71
72Patches are encouraged, and may be submitted by forking this project and
73submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
74
75License
76-------
77
78Copyright 2014 The Android Open Source Project, Inc.
79
80Licensed to the Apache Software Foundation (ASF) under one or more contributor
81license agreements.  See the NOTICE file distributed with this work for
82additional information regarding copyright ownership.  The ASF licenses this
83file to you under the Apache License, Version 2.0 (the "License"); you may not
84use this file except in compliance with the License.  You may obtain a copy of
85the License at
86
87http://www.apache.org/licenses/LICENSE-2.0
88
89Unless required by applicable law or agreed to in writing, software
90distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
91WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
92License for the specific language governing permissions and limitations under
93the License.
94