使用 Snapshot API 獲取當前使用者活動
對於使用者身體活動的一次性非常量請求,請使用 Snapshot API:
// Remember to initialize your client as described in the Remarks section
Awareness.SnapshotApi.getDetectedActivity(client)
.setResultCallback(new ResultCallback<DetectedActivityResult>() {
@Override
public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
if (!detectedActivityResult.getStatus().isSuccess()) {
Log.e(getClass().getSimpleName(), "Could not get the current activity.");
return;
}
ActivityRecognitionResult result = detectedActivityResult
.getActivityRecognitionResult();
DetectedActivity probableActivity = result.getMostProbableActivity();
Log.i(getClass().getSimpleName(), "Activity received : " +
probableActivity.toString());
}
});