I am using expo pedometer but I have two problems:
It doesn't seem to count the steps,the steps count is always zero.
The
Pedometer.getStepCountAsync
function isn't supported in android.
I am using
- "expo": "~44.0.0"
- "expo-sensors": "~11.1.0"
- "react": "17.0.1"
- "react-dom": "17.0.1"
- "react-native": "0.64.3"
- my mobile android version is 11
Here's my code
import { Pedometer } from "expo-sensors";
export default function HomeScreen() {
const [pedometerAvailability, setPedometerAvailability] = useState("");
const [stepsCount, setStepsCount] = useState(0);
useEffect(() => {
subscribe();
return () => {};
}, []);
const subscribe = () => {
const subscription = Pedometer.watchStepCount((result) => {
setStepsCount(result.steps);
});
Pedometer.isAvailableAsync().then(
(result) => {
setPedometerAvailability(String(result));
},
(error) => {
setPedometerAvailability("Could not get isPedometerAvailable: " + error);
}
);
};
return (
<Text>{stepsCount}</Text>
)
}
just give permission to track steps