RookStepCounter
RookStepsCounter
RookStepsCounter is the Android-only API for the native Rook steps counter.
Use it when you want to:
- Check whether the current Android device supports the Rook steps counter.
- Enable or disable the native step counter.
- Check whether the step counter is active.
- Read today's step count collected by the step counter.
Platform availability
RookStepsCounter is only available on Android.
It should not be called from iOS code paths.
For shared Ionic or Capacitor apps, guard access with a platform check:
import { Capacitor } from '@capacitor/core';
import { RookStepsCounter } from 'capacitor-rook-sdk';
const isAndroid = Capacitor.getPlatform() === 'android';
if (isAndroid) {
const availability = await RookStepsCounter.isRookStepsCounterAvailable();
console.log(availability.result);
}
Prerequisite
Initialize Rook before using this object. If Rook has not been initialized, the native Android layer rejects the call with an initialization error.
import { RookConfig } from 'capacitor-rook-sdk';
await RookConfig.initRook({
clientUUID: 'YOUR_CLIENT_UUID',
secret: 'YOUR_SECRET_KEY',
environment: 'sandbox',
});
Recommended flow
- Verify that the app is running on Android.
- Initialize Rook with
RookConfig.initRook(...). - Call
RookStepsCounter.isRookStepsCounterAvailable()before showing step-counter actions in the UI. - Enable the counter with
RookStepsCounter.enableRookStepsCounter(). - Confirm the current status with
RookStepsCounter.isRookStepsCounterActive(). - Read today's steps with
RookStepsCounter.getRookTodayStepsCount(). - Disable the counter with
RookStepsCounter.disableRookStepsCounter()when needed.
API reference
isRookStepsCounterAvailable()
Returns a BoolResult with the shape { result: boolean }.
true: the current Android device supports the Rook steps counter.false: the steps counter is not available on this device.
isRookStepsCounterActive()
Returns a BoolResult with the shape { result: boolean }.
true: the steps counter is currently enabled.false: the steps counter is currently disabled.
enableRookStepsCounter()
Enables the native Rook steps counter and returns a BoolResult.
true: the enable operation succeeded.false: the enable operation did not succeed.
disableRookStepsCounter()
Disables the native Rook steps counter and returns a BoolResult.
true: the disable operation succeeded.false: the disable operation did not succeed.
getRookTodayStepsCount()
Returns a StepsResult with the shape { stepCount: number }.
The stepCount value is today's total steps reported by the native Rook steps counter.
Example
import { Capacitor } from '@capacitor/core';
import { RookConfig, RookStepsCounter } from 'capacitor-rook-sdk';
async function setupStepsCounter() {
if (Capacitor.getPlatform() !== 'android') return;
await RookConfig.initRook({
clientUUID: 'YOUR_CLIENT_UUID',
secret: 'YOUR_SECRET_KEY',
environment: 'sandbox',
});
const availability = await RookStepsCounter.isRookStepsCounterAvailable();
if (!availability.result) {
return;
}
await RookStepsCounter.enableRookStepsCounter();
const active = await RookStepsCounter.isRookStepsCounterActive();
const todaySteps = await RookStepsCounter.getRookTodayStepsCount();
console.log('Steps counter active:', active.result);
console.log('Today steps:', todaySteps.stepCount);
}
Migration from deprecated Health Connect step methods
If you are still using step methods from RookHealthConnect, migrate to RookStepsCounter:
| Deprecated method | Use instead |
|---|---|
RookHealthConnect.syncTodayAndroidStepsCount() | RookStepsCounter.getRookTodayStepsCount() |
RookHealthConnect.enableBackgroundAndroidSteps() | RookStepsCounter.enableRookStepsCounter() |
RookHealthConnect.disableBackgroundAndroidSteps() | RookStepsCounter.disableRookStepsCounter() |
RookHealthConnect.isBackgroundAndroidStepsActive() | RookStepsCounter.isRookStepsCounterActive() |
Notes for other developers
- Prefer
RookStepsCounterfor Android step-counter features instead of the deprecatedRookHealthConnectstep methods. - Check availability before enabling the feature, since support can vary by device.
- Keep Android guards close to the call site in shared codebases to avoid accidental iOS calls.