Skip to content

Most visited

Recently visited

navigation

PermissionRequest

public abstract class PermissionRequest
extends Object

java.lang.Object
   ↳ android.webkit.PermissionRequest


This class defines a permission request and is used when web content requests access to protected resources. The permission request related events are delivered via onPermissionRequest(PermissionRequest) and onPermissionRequestCanceled(PermissionRequest). Either grant() or deny() must be called in UI thread to respond to the request. New protected resources whose names are not defined here may be requested in future versions of WebView, even when running on an older Android release. To avoid unintentionally granting requests for new permissions, you should pass the specific permissions you intend to grant to grant(), and avoid writing code like this example:

 permissionRequest.grant(permissionRequest.getResources())  // This is wrong!!!
 
See the WebView's release notes for information about new protected resources.

Summary

Constants

String RESOURCE_AUDIO_CAPTURE

Resource belongs to audio capture device, like microphone.

String RESOURCE_MIDI_SYSEX

Resource will allow sysex messages to be sent to or received from MIDI devices.

String RESOURCE_PROTECTED_MEDIA_ID

Resource belongs to protected media identifier.

String RESOURCE_VIDEO_CAPTURE

Resource belongs to video capture device, like camera.

Public constructors

PermissionRequest()

Public methods

abstract void deny()

Call this method to deny the request.

abstract Uri getOrigin()

Call this method to get the origin of the web page which is trying to access the restricted resources.

abstract String[] getResources()

Call this method to get the resources the web page is trying to access.

abstract void grant(String[] resources)

Call this method to grant origin the permission to access the given resources.

Inherited methods

From class java.lang.Object

Constants

RESOURCE_AUDIO_CAPTURE

added in API level 21
String RESOURCE_AUDIO_CAPTURE

Resource belongs to audio capture device, like microphone.

Constant Value: "android.webkit.resource.AUDIO_CAPTURE"

RESOURCE_MIDI_SYSEX

added in API level 23
String RESOURCE_MIDI_SYSEX

Resource will allow sysex messages to be sent to or received from MIDI devices. These messages are privileged operations, e.g. modifying sound libraries and sampling data, or even updating the MIDI device's firmware. Permission may be requested for this resource in API levels 21 and above, if the Android device has been updated to WebView 45 or above.

Constant Value: "android.webkit.resource.MIDI_SYSEX"

RESOURCE_PROTECTED_MEDIA_ID

added in API level 21
String RESOURCE_PROTECTED_MEDIA_ID

Resource belongs to protected media identifier. After the user grants this resource, the origin can use EME APIs to generate the license requests.

Constant Value: "android.webkit.resource.PROTECTED_MEDIA_ID"

RESOURCE_VIDEO_CAPTURE

added in API level 21
String RESOURCE_VIDEO_CAPTURE

Resource belongs to video capture device, like camera.

Constant Value: "android.webkit.resource.VIDEO_CAPTURE"

Public constructors

PermissionRequest

added in API level 21
PermissionRequest ()

Public methods

deny

added in API level 21
void deny ()

Call this method to deny the request.

getOrigin

added in API level 21
Uri getOrigin ()

Call this method to get the origin of the web page which is trying to access the restricted resources.

Returns
Uri the origin of web content which attempt to access the restricted resources.

getResources

added in API level 21
String[] getResources ()

Call this method to get the resources the web page is trying to access.

Returns
String[] the array of resources the web content wants to access.

grant

added in API level 21
void grant (String[] resources)

Call this method to grant origin the permission to access the given resources. The granted permission is only valid for this WebView.

Parameters
resources String: the resources granted to be accessed by origin, to grant request, the requested resources returned by getResources() must be equals or a subset of granted resources. This parameter is designed to avoid granting permission by accident especially when new resources are requested by web content.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)