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)
{
// Check geolocation permission status
PermissionsApi.query(this, "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 voidquery(HtmlPage page, PermissionsListener listener, String permissionName) Queries the status of a permission.static voidquery(PermissionsListener listener, String permissionName) Queries the status of a permission using the current page context.static voidqueryAll(HtmlPage page, PermissionsListener listener, String... permissionNames) Queries multiple permissions.static voidqueryAll(PermissionsListener listener, String... permissionNames) Queries multiple permissions using the current page context.static voidqueryCamera(HtmlPage page, PermissionsListener listener) Queries the camera permission status.static voidqueryCamera(PermissionsListener listener) Queries the camera permission status using the current page context.static voidqueryGeolocation(HtmlPage page, PermissionsListener listener) Queries the geolocation permission status.static voidqueryGeolocation(PermissionsListener listener) Queries the geolocation permission status using the current page context.static voidqueryMicrophone(HtmlPage page, PermissionsListener listener) Queries the microphone permission status.static voidqueryMicrophone(PermissionsListener listener) Queries the microphone permission status using the current page context.static voidqueryNotifications(HtmlPage page, PermissionsListener listener) Queries the notifications permission status.static voidqueryNotifications(PermissionsListener listener) Queries the notifications permission status using the current page context.
-
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:
listener- The listener 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.listener- The listener 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:
listener- The listener that will receive the status event.
-
queryGeolocation
Queries the geolocation permission status.- Parameters:
page- The page context.listener- The listener that will receive the status event.
-
queryNotifications
Queries the notifications permission status using the current page context.- Parameters:
listener- The listener that will receive the status event.
-
queryNotifications
Queries the notifications permission status.- Parameters:
page- The page context.listener- The listener that will receive the status event.
-
queryCamera
Queries the camera permission status using the current page context.- Parameters:
listener- The listener that will receive the status event.
-
queryCamera
Queries the camera permission status.- Parameters:
page- The page context.listener- The listener that will receive the status event.
-
queryMicrophone
Queries the microphone permission status using the current page context.- Parameters:
listener- The listener that will receive the status event.
-
queryMicrophone
Queries the microphone permission status.- Parameters:
page- The page context.listener- The listener that will receive the status event.
-
queryAll
Queries multiple permissions using the current page context.- Parameters:
listener- The listener that will receive the status events.permissionNames- The names of the permissions to query.
-
queryAll
Queries multiple permissions.- Parameters:
page- The page context.listener- The listener that will receive the status events.permissionNames- The names of the permissions to query.
-