expo-activity-motion
v1.2.3
Published
Background **activity transition** detection for Expo SDK 56+:
Maintainers
Readme
expo-activity-motion
Background activity transition detection for Expo SDK 56+:
| Platform | API | Survives process death |
|----------|-----|------------------------|
| Android | Activity Recognition Transition API + PendingIntent | Yes (days) |
| iOS | CMMotionActivityManager live updates + historical query | Live while process lives; history on next wake |
Events are delivered to a expo-task-manager task so your JS runs even when the UI is not mounted.
Install
npx expo install expo-task-manager
npm install expo-activity-motionConfig plugin (permisos por defecto)
{
"expo": {
"plugins": [
"expo-task-manager",
[
"expo-activity-motion",
{
"motionPermission": "Necesitamos movimiento para detectar caminata y conducción.",
"enableBootReceiver": false
}
]
]
}
}O simplemente:
{
"expo": {
"plugins": ["expo-task-manager", "expo-activity-motion"]
}
}| Opción | Default | Efecto |
|--------|---------|--------|
| motionPermission | texto en inglés | NSMotionUsageDescription (iOS) |
| enableBootReceiver | true | RECEIVE_BOOT_COMPLETED + re-registro tras reboot |
npx expo prebuild --clean
npx expo run:androidNo funciona en Expo Go.
Usage
import * as TaskManager from 'expo-task-manager';
import * as ActivityMotion from 'expo-activity-motion';
const TASK = 'activity-motion-task';
TaskManager.defineTask(TASK, async ({ data, error }) => {
if (error) return;
const { transitions } = data as {
transitions: Array<{
activityType: string;
transitionType: 'enter' | 'exit';
timestamp: number;
}>;
};
console.log(transitions);
});
await ActivityMotion.requestPermissionsAsync();
await ActivityMotion.startActivityTransitionsAsync(TASK);API
| Method | Description |
|--------|-------------|
| isAvailableAsync() | Play Services / Core Motion present |
| getPermissionsAsync() / requestPermissionsAsync() | Motion permissions |
| startActivityTransitionsAsync(taskName) | Start background tracking |
| stopActivityTransitionsAsync(taskName) | Stop |
| hasStartedActivityTransitionsAsync(taskName) | Status |
| reregisterActivityTransitionsAsync(taskName?) | Re-bind if OS dropped registration |
