Package com.oorian.html.js.permissions
Class PermissionsApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.permissions.PermissionsApi
Provides access to the Permissions API from server-side Java code.
The Permissions API allows querying and monitoring the status of various browser permissions. It provides a consistent way to check if a feature is available before attempting to use it.
Supported Permission Names:
- geolocation: Access to device location
- notifications: Display notifications
- camera: Access to camera
- microphone: Access to microphone
- persistent-storage: Use persistent storage
- push: Receive push messages
- screen-wake-lock: Keep screen on
Usage:
public class MyPage extends HtmlPage implements PermissionsListener {
@Override
protected void createBody(Body body) {
body.registerListener(this, PermissionStatusEvent.class);
// Check geolocation permission status
PermissionsApi.query(body, "geolocation");
}
@Override
public void onEvent(PermissionStatusEvent event) {
String permission = event.getPermissionName();
String state = event.getState();
switch (state) {
case "granted":
// Permission granted, can use the feature
break;
case "prompt":
// User will be prompted when feature is used
break;
case "denied":
// Permission denied, feature unavailable
break;
}
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidQueries the status of a permission using the current page context.static voidQueries the status of a permission.static voidQueries multiple permissions using the current page context.static voidQueries multiple permissions.static voidqueryCamera(Element element) Queries the camera permission status using the current page context.static voidqueryCamera(HtmlPage page, Element element) Queries the camera permission status.static voidqueryGeolocation(Element element) Queries the geolocation permission status using the current page context.static voidqueryGeolocation(HtmlPage page, Element element) Queries the geolocation permission status.static voidqueryMicrophone(Element element) Queries the microphone permission status using the current page context.static voidqueryMicrophone(HtmlPage page, Element element) Queries the microphone permission status.static voidqueryNotifications(Element element) Queries the notifications permission status using the current page context.static voidqueryNotifications(HtmlPage page, Element element) Queries the notifications permission status.
-
Field Details
-
GEOLOCATION
- See Also:
-
NOTIFICATIONS
- See Also:
-
CAMERA
- See Also:
-
MICROPHONE
- See Also:
-
PERSISTENT_STORAGE
- See Also:
-
PUSH
- See Also:
-
SCREEN_WAKE_LOCK
- See Also:
-
STATE_GRANTED
- See Also:
-
STATE_DENIED
- See Also:
-
STATE_PROMPT
- See Also:
-
-
Constructor Details
-
PermissionsApi
public PermissionsApi()
-
-
Method Details
-
query
Queries the status of a permission using the current page context.- Parameters:
element- The element that will receive the status event.permissionName- The name of the permission to query.
-
query
Queries the status of a permission.- Parameters:
page- The page context.element- The element that will receive the status event.permissionName- The name of the permission to query.
-
queryGeolocation
Queries the geolocation permission status using the current page context.- Parameters:
element- The element that will receive the status event.
-
queryGeolocation
Queries the geolocation permission status.- Parameters:
page- The page context.element- The element that will receive the status event.
-
queryNotifications
Queries the notifications permission status using the current page context.- Parameters:
element- The element that will receive the status event.
-
queryNotifications
Queries the notifications permission status.- Parameters:
page- The page context.element- The element that will receive the status event.
-
queryCamera
Queries the camera permission status using the current page context.- Parameters:
element- The element that will receive the status event.
-
queryCamera
Queries the camera permission status.- Parameters:
page- The page context.element- The element that will receive the status event.
-
queryMicrophone
Queries the microphone permission status using the current page context.- Parameters:
element- The element that will receive the status event.
-
queryMicrophone
Queries the microphone permission status.- Parameters:
page- The page context.element- The element that will receive the status event.
-
queryAll
Queries multiple permissions using the current page context.- Parameters:
element- The element that will receive the status events.permissionNames- The names of the permissions to query.
-
queryAll
Queries multiple permissions.- Parameters:
page- The page context.element- The element that will receive the status events.permissionNames- The names of the permissions to query.
-