Package com.oorian.html.js.wakelock
Class WakeLockApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.wakelock.WakeLockApi
Provides access to the Screen Wake Lock API from server-side Java code.
The Screen Wake Lock API prevents the device from dimming or locking the screen. This is useful for applications that need to keep the screen on, such as:
- Video players
- Navigation apps
- Presentation apps
- Recipe apps (cooking mode)
Note: The wake lock is automatically released when the page becomes hidden (e.g., user switches tabs). You may want to re-acquire it when the page becomes visible again.
Usage:
public class MyPage extends HtmlPage implements WakeLockListener {
@Override
protected void createBody(Body body) {
body.registerListener(this, WakeLockEvent.class);
body.registerListener(this, WakeLockErrorEvent.class);
// Acquire wake lock to keep screen on
WakeLockApi.request(body);
}
@Override
public void onEvent(WakeLockEvent event) {
if (event.isAcquired()) {
showMessage("Screen will stay on");
} else {
showMessage("Wake lock released");
}
}
@Override
public void onEvent(WakeLockErrorEvent event) {
showMessage("Wake lock failed: " + event.getMessage());
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks if the Screen Wake Lock API is supported by the browser using the current page context.static voidcheckSupport(HtmlPage page) Checks if the Screen Wake Lock API is supported by the browser.static voidReleases the current wake lock using the current page context.static voidReleases the current wake lock.static voidRequests a screen wake lock using the current page context.static voidRequests a screen wake lock.
-
Constructor Details
-
WakeLockApi
public WakeLockApi()
-
-
Method Details
-
request
Requests a screen wake lock using the current page context.Once acquired, the screen will not dim or lock until the wake lock is released or the page becomes hidden.
- Parameters:
element- The element that will receive wake lock events.
-
request
Requests a screen wake lock.Once acquired, the screen will not dim or lock until the wake lock is released or the page becomes hidden.
- Parameters:
page- The page context.element- The element that will receive wake lock events.
-
release
Releases the current wake lock using the current page context.- Parameters:
element- The element that will receive the release event.
-
release
Releases the current wake lock.- Parameters:
page- The page context.element- The element that will receive the release event.
-
checkSupport
public static void checkSupport()Checks if the Screen Wake Lock API is supported by the browser using the current page context.Note: This executes JavaScript that logs to console.
-
checkSupport
Checks if the Screen Wake Lock API is supported by the browser.Note: This executes JavaScript that logs to console.
- Parameters:
page- The page context.
-