Skip to content

Most visited

Recently visited

navigation

UserSensor.Builder

UserSensor.Builder

public static class UserSensor.Builder
extends Object

java.lang.Object
   ↳ com.google.android.things.userdriver.UserSensor.Builder


Builder to allow for flexible UserSensor construction. Most parameters are given default values and can be skipped if not needed. The only required calls are setDriver(UserSensorDriver) and either setType(int) or setCustomType(int, String, int). See the Sensor HAL documentation for details on how each parameter is used. Usage will look something like this: UserSensor sensor = new UserSensor.Builder() .setName("ABC123 Accelerometer") .setType(Sensor.TYPE_ACCELEROMETER) .setDriver(myDriverObject) .build();

Summary

Public constructors

UserSensor.Builder()

Constructor; use new UserSensor.Builder() to get a new Builder.

Public methods

UserSensor build()

Returns a new UserSensor with the configured parameters.

UserSensor.Builder setCustomType(int type, String stringType, int reportingMode)

Sets a custom driver type and reporting mode.

UserSensor.Builder setDriver(UserSensorDriver driver)

Sets the UserSensorDriver that controls the sensor.

UserSensor.Builder setMaxDelay(int maxDelay)

Sets the maximum allowed delay between sensor reads in microseconds.

UserSensor.Builder setMaxRange(float maxRange)

Sets the max sensor range.

UserSensor.Builder setMinDelay(int minDelay)

Sets the minimum allowed delay between sensor reads in microseconds.

UserSensor.Builder setName(String name)

Sets the sensor name.

UserSensor.Builder setPower(float power)

Sets the power cost of enabling the sensor in milliAmps.

UserSensor.Builder setRequiredPermission(String requiredPermission)

Sets a permission that will be required to read this sensor.

UserSensor.Builder setResolution(float resolution)

Sets the sensor resolution.

UserSensor.Builder setType(int type)

Sets the driver type.

UserSensor.Builder setUuid(UUID uuid)

Sets a UUID to identify this sensor.

UserSensor.Builder setVendor(String vendor)

Sets the driver vendor name.

UserSensor.Builder setVersion(int version)

Sets the driver version.

Inherited methods

From class java.lang.Object

Public constructors

UserSensor.Builder

UserSensor.Builder ()

Constructor; use new UserSensor.Builder() to get a new Builder.

Public methods

build

UserSensor build ()

Returns a new UserSensor with the configured parameters.

Returns
UserSensor A new UserSensor object.

setCustomType

UserSensor.Builder setCustomType (int type, 
                String stringType, 
                int reportingMode)

Sets a custom driver type and reporting mode. This can be used to install a custom driver type that is not currently defined as an Android sensor, e.g. a radiation detector. It's up to the sensor to define what the returned float array represents and the user to interpret these values correctly.

Parameters
type int: An int value to represent this sensor type. Must be greater than or equal to Sensor.TYPE_DEVICE_PRIVATE_BASE. Used by SensorManager.getDynamicSensorList() to return only the sensors that match the given type.
stringType String: A string identifying the sensor type in reverse-domain format, e.g. com.companyname.radiationdetector.
reportingMode int: One of the Sensor.REPORTING_MODE_* constants.
Returns
UserSensor.Builder The same builder instance.
Throws
IllegalArgumentException if type is invalid or stringType is null.

setDriver

UserSensor.Builder setDriver (UserSensorDriver driver)

Sets the UserSensorDriver that controls the sensor.

Parameters
driver UserSensorDriver
Returns
UserSensor.Builder The same builder instance.

setMaxDelay

UserSensor.Builder setMaxDelay (int maxDelay)

Sets the maximum allowed delay between sensor reads in microseconds.

Parameters
maxDelay int
Returns
UserSensor.Builder The same builder instance.

setMaxRange

UserSensor.Builder setMaxRange (float maxRange)

Sets the max sensor range. The sensor should be able to report values without saturating within [-maxRange, maxRange].

Parameters
maxRange float: The maximum sensor range in the sensor's reporting units.
Returns
UserSensor.Builder The same builder instance.

See also:

setMinDelay

UserSensor.Builder setMinDelay (int minDelay)

Sets the minimum allowed delay between sensor reads in microseconds.

Parameters
minDelay int
Returns
UserSensor.Builder The same builder instance.

setName

UserSensor.Builder setName (String name)

Sets the sensor name. Usually contains the part name and sensor type, e.g. "ABC001 Accelerometer".

Parameters
name String
Returns
UserSensor.Builder The same builder instance.

setPower

UserSensor.Builder setPower (float power)

Sets the power cost of enabling the sensor in milliAmps.

Parameters
power float
Returns
UserSensor.Builder The same builder instance.

setRequiredPermission

UserSensor.Builder setRequiredPermission (String requiredPermission)

Sets a permission that will be required to read this sensor. The framework may force a set permission for certain sensors, e.g. heart rate monitors, and disregard any manually set permissions.

Parameters
requiredPermission String: A string permission name, or empty for no permission needed.
Returns
UserSensor.Builder The same builder instance.

setResolution

UserSensor.Builder setResolution (float resolution)

Sets the sensor resolution. Sensor resolution is the smallest discernable difference the sensor can measure. Usually calculated based on max range and the number of bits available.

Parameters
resolution float: The sensor resolution in the sensor's reporting units.
Returns
UserSensor.Builder The same builder instance.

See also:

setType

UserSensor.Builder setType (int type)

Sets the driver type. Use this to set the driver to be a known Android sensor type. For custom sensor types, use setCustomType(int, String, int) instead.

Parameters
type int: Android sensor type.
Returns
UserSensor.Builder The same builder instance.
Throws
IllegalArgumentException if the given type is deprecated or unknown.

setUuid

UserSensor.Builder setUuid (UUID uuid)

Sets a UUID to identify this sensor. This is only useful when multiple sensors of the exact same type are connected, to be able to distinguish between them. Normally this can be left at the default 0. Apps will not see this value directly, but can use Sensor.getId() to distinguish between sensors that have non-zero UUIDs.

Parameters
uuid UUID: A UUID to assign this sensor, or null for 0.
Returns
UserSensor.Builder The same builder instance.

setVendor

UserSensor.Builder setVendor (String vendor)

Sets the driver vendor name.

Parameters
vendor String
Returns
UserSensor.Builder The same builder instance.

setVersion

UserSensor.Builder setVersion (int version)

Sets the driver version.

Parameters
version int
Returns
UserSensor.Builder The same builder instance.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.