Plug-in Overview

This plug-in enables your app to detect the battery level of the device. The plug-in fires automatic events any time the device detects a battery level change. You can also query the plug-in for the current battery level at any time.

  • Plug-in ID: org.ambientdynamix.contextplugins.batterylevel

Supported Context Types

Context Types Privacy Risk Level Data Types Description
<PLUGID> LOW IBatteryLevelInfo Provides battery level data as described in the IBatteryLevelInfo interface below
Descriptions of the data types above can be found in the JavaDocs at the end of this page.

Web App Usage

Integrate Dynamix into your Web app, as described here.

Add context support as follows:

Your app will automatically receive an event whenever the device’s battery level changes. You can also query for the current battery level at any time using the following code:

See the JavaDocs below for details on the available context event data. Context events can be handled like this in your Web app’s dynamix_listener.js file:

Native App Usage

Integrate Dynamix into your native app, as described here.

Add context support as follows:

Your app will automatically receive an event whenever the device’s battery level changes. You can also query for the current battery level at any time using the following code:

[DataType JAR Download data-type-download=””]

Context events can be handled like this:

JavaDocs

Web apps

Web apps will receive context events with additional JavaScript properties, which are automatically derived from the IBatteryLevelInfo interface described in the JavaDocs below if the methods adhere to JavaBean getter conventions. The available JavaScript properties can be derived as follows:

  • Remove each method’s ‘get’ prefix.
  • Remove each method’s trailing parentheses ‘()’.
  • Convert the result to camel case.
  • Example: event.getSomeProperty() would be available in JavaScript as event.someProperty;

Native apps

Native apps can use the interface below directly, if the plug-in’s data-type JAR is included on the app’s build path and exported into the app’s APK.

JavaDocs