Use this class to create activity-based fences.
Note: Values that indicate a changing state are momentarily TRUE
for about 5 seconds, then automatically revert to FALSE
.
Constant Summary
int | IN_VEHICLE | The device is in a vehicle, such as a car. |
int | ON_BICYCLE | The device is on a bicycle. |
int | ON_FOOT | The device is on a user who is walking or running. |
int | RUNNING | The device is on a user who is running. |
int | STILL | The device is still (not moving). |
int | UNKNOWN | Unable to detect the current activity. |
int | WALKING | The device is on a user who is walking. |
Public Method Summary
static AwarenessFence | |
static AwarenessFence | |
static AwarenessFence |
Inherited Method Summary
Constants
public static final int IN_VEHICLE
The device is in a vehicle, such as a car.
public static final int ON_BICYCLE
The device is on a bicycle.
public static final int ON_FOOT
The device is on a user who is walking or running.
public static final int RUNNING
The device is on a user who is running. This is a sub-activity of
ON_FOOT
.
public static final int STILL
The device is still (not moving).
public static final int UNKNOWN
Unable to detect the current activity.
public static final int WALKING
The device is on a user who is walking. This is a sub-activity of
ON_FOOT
.
Public Methods
public static AwarenessFence during (int... activityTypes)
This fence is in the TRUE
state when the user is currently engaged in one of the specified
activityTypes
, and FALSE
otherwise.
To call this function, a different permission is required depending on your Android API level:
- For Android 10 (API level 29) and later: android.permission.ACTIVITY_RECOGNITION permission
- For Android 9 (API level 28) and earlier: com.google.android.gms.permission.ACTIVITY_RECOGNITION permission
Parameters
activityTypes | Collection of activity type constants. Valid values are the constants defined in this class. |
---|
Returns
- Awareness fence.
public static AwarenessFence starting (int... activityTypes)
This fence is momentarily (about 5 seconds) TRUE
when the user begins to engage in one of the activityTypes
and the
previous activity was not one of the values in activityTypes
.
To call this function, a different permission is required depending on your Android API level:
- For Android 10 (API level 29) and later: android.permission.ACTIVITY_RECOGNITION permission
- For Android 9 (API level 28) and earlier: com.google.android.gms.permission.ACTIVITY_RECOGNITION permission
Parameters
activityTypes | Collection of activity type constants. Valid values are the constants defined in this class. |
---|
Returns
- Awareness fence.
public static AwarenessFence stopping (int... activityTypes)
This fence is momentarily (about 5 seconds) TRUE
when the user stops one of the activityTypes
, and transitions to an
activity that is not in activityTypes
.
To call this function, a different permission is required depending on your Android API level:
- For Android 10 (API level 29) and later: android.permission.ACTIVITY_RECOGNITION permission
- For Android 9 (API level 28) and earlier: com.google.android.gms.permission.ACTIVITY_RECOGNITION permission
Parameters
activityTypes | Collection of activity type constants. Valid values are the constants defined in this class. |
---|
Returns
- Awareness fence.