Class PermissionsApi

java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.permissions.PermissionsApi

public class PermissionsApi extends JavaScriptApi
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 Details

  • Constructor Details

    • PermissionsApi

      public PermissionsApi()
  • Method Details

    • query

      public static void query(Element element, String permissionName)
      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

      public static void query(HtmlPage page, Element element, String permissionName)
      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

      public static void queryGeolocation(Element element)
      Queries the geolocation permission status using the current page context.
      Parameters:
      element - The element that will receive the status event.
    • queryGeolocation

      public static void queryGeolocation(HtmlPage page, Element element)
      Queries the geolocation permission status.
      Parameters:
      page - The page context.
      element - The element that will receive the status event.
    • queryNotifications

      public static void queryNotifications(Element element)
      Queries the notifications permission status using the current page context.
      Parameters:
      element - The element that will receive the status event.
    • queryNotifications

      public static void queryNotifications(HtmlPage page, Element element)
      Queries the notifications permission status.
      Parameters:
      page - The page context.
      element - The element that will receive the status event.
    • queryCamera

      public static void queryCamera(Element element)
      Queries the camera permission status using the current page context.
      Parameters:
      element - The element that will receive the status event.
    • queryCamera

      public static void queryCamera(HtmlPage page, Element element)
      Queries the camera permission status.
      Parameters:
      page - The page context.
      element - The element that will receive the status event.
    • queryMicrophone

      public static void queryMicrophone(Element element)
      Queries the microphone permission status using the current page context.
      Parameters:
      element - The element that will receive the status event.
    • queryMicrophone

      public static void queryMicrophone(HtmlPage page, Element element)
      Queries the microphone permission status.
      Parameters:
      page - The page context.
      element - The element that will receive the status event.
    • queryAll

      public static void queryAll(Element element, String... permissionNames)
      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

      public static void queryAll(HtmlPage page, Element element, String... permissionNames)
      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.