对于一次非恒定的用户身体活动请求,请使用Snapshot API:
// 请记住按照“备注”部分所述初始化客户端。 Awareness.SnapshotApi.getDetectedActivity(client) .setResultCallback(new ResultCallback<DetectedActivityResult>() { @Override public void onResult(@NonNull DetectedActivityResult detectedActivityResult) { if (!detectedActivityResult.getStatus().isSuccess()) { Log.e(getClass().getSimpleName(), "无法获取当前活动。"); return; } ActivityRecognitionResult result = detectedActivityResult .getActivityRecognitionResult(); DetectedActivity probableActivity = result.getMostProbableActivity(); Log.i(getClass().getSimpleName(), "收到的活动: " + probableActivity.toString()); } });