react-native-background-geolocation: BackgroundGeolocation.onActivityChange is not detecting any activity on android
Your Environment
- Plugin version: ^4.9.4
- Platform: Android
- OS version: 10.0.1
- Device manufacturer / model: One Plus 5T
- React Native version (
react-native -v
): 0.68.5 - Plugin config
import React, { useEffect, useState } from 'react';
import BackgroundGeolocation, { Subscription } from 'react-native-background-geolocation';
import { Text } from 'components/commons';
import constStyles from 'constants/Styles';
import colors from 'constants/Colors';
const App = () => {
const [message, setMessage] = useState('Please wait...');
useEffect(() => {
const onActivityChange: Subscription = BackgroundGeolocation.onActivityChange(event => {
console.log('[onMotionChange]', event);
setMessage(`${event.activity}: ${event.confidence}%`);
});
// eslint-disable-next-line @typescript-eslint/no-floating-promises
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
activityRecognitionInterval: 1000,
debug: true, // <-- enable debug sounds/notifications
}).then(state => {
console.log('BackgroundGeolocation is configured and ready: ', state.enabled, state);
if (!state.enabled) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
BackgroundGeolocation.start(() => console.log('BackgroundGeolocation Start success', state.enabled));
}
});
return () => {
onActivityChange.remove();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
BackgroundGeolocation.stop(() => console.log('BackgroundGeolocation Stop success'));
};
}, []);
return (
<Text style={constStyles.font32} color={colors.skyblue}>
{message}
</Text>
);
};
export default App;
Expected Behavior
I followed all the instructions mentioned here BackgroundGeolocation.onActivityChange didn’t detect anything on android, but it works on ios.
Actual Behavior
It doesn’t log anything inside the onActivityChange
method
Steps to Reproduce
Context
Trying to display if it detect if i’m on a vehicle on android phone
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (9 by maintainers)
The only acceptable Setup Guides are linked in the README. Anything not linked are deprecated and due to be removed.
There is nothing mysterious about
playServicesLocationVersion 21+
. Google simply made a breaking change in v21, modifying a particular javaClass
to anInterface
. Importingv21+
requires that EVERY OTHER PLUGIN importingplay-services-location
must also importv21+
. Not every plugin takes care to offer a convenient way to control the imported version as done here in my plugin withext.playServicesLocationVersion
– some other plugins naïvely hard-code the imported version.When one plugin imports
v20
and another importsv21
, your app will have a runtime error.This plugin is perfectly willing and able to operate with either
v20
orv21
. The question is, are ALL your OTHER plugins also able to do this?