michaelmika / react-native-simple-native-geofencing

a native geofencing module for react-native
38 stars 20 forks source link

entry and exit not working. #14

Open ShijeshiLeaf opened 4 years ago

ShijeshiLeaf commented 4 years ago

Hi, I want to implement the geofence in my application. So I created a sample app to test the functionality. I got start notification in my notification bar. But not entry and exit notifications. Could you please help me to find the solution?

`class App extends Component { componentWillMount () { // see above if (Platform.OS === 'android') { this.requestLocationPermission() } } componentDidMount () { // set up Notifications RNSimpleNativeGeofencing.initNotification({ channel: { title: 'Message Channel Title', description: 'Message Channel Description' }, start: { notify: true, title: 'Start Tracking', description: 'You are now tracked' }, stop: { notify: true, title: 'Stopped Tracking', description: 'You are not tracked any longer' }, enter: { notify: true, title: 'Attention', // [value] will be replaced ob geofences' value attribute description: 'You entered a [value] Zone' }, exit: { notify: true, title: 'Left Zone', description: 'You left a [value] Zone' } }) this.startMonitoring() }

async requestLocationPermission () { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { title: 'Location permission', message: 'Needed obviously' } ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('Granted Permission') } else { console.log('Denied Permission') } } catch (err) { console.warn(err) } }

fail () { console.log('Fail to start geofencing') alert('Fail to start geofencing') }

startMonitoring () { let geofences = [ { key: 'geoNum1', latitude: 38.9204, longitude: -77.0175, radius: 200, value: 'yellow' }, { key: 'geoNum2', latitude: 38.9248, longitude: -77.0258, radius: 100, value: 'green' }, { key: 'geoNum3', latitude: 47.423, longitude: -122.084, radius: 150, value: 'red' } ] RNSimpleNativeGeofencing.addGeofences(geofences, 3000000, this.fail) }

stopMonitoring () { RNSimpleNativeGeofencing.removeAllGeofences() }

render () { return } }

export default App`

This is my code. react-native version : 0.62.0 device OS : Android 9 Pie

calypsow777 commented 4 years ago

It doesn't work on Android when the app is in the background because of that: https://stackoverflow.com/questions/46935145/geofence-transition-pendingintent-blocked-by-the-os-on-android-oreo

ShijeshiLeaf commented 4 years ago

It doesn't work when the app is in foreground too.

calypsow777 commented 4 years ago

Did you add <service android:name="com.simplegeofencing.reactnative.GeofenceTransitionsIntentService"/> <service android:name="com.simplegeofencing.reactnative.ShowTimeoutNotification" /> in the manifest ? Can you see errors in the logs? (maybe try adb logcat | grep geofenc)

ShijeshiLeaf commented 4 years ago

Yes. I add. I couldn't see any error logs. I got the notification of start activity and stop activity. didn't get the entry and exit to a region.

gusilveiramp commented 4 years ago

Hi, it's working perfectly (on Android) with these changes: https://github.com/michaelmika/react-native-simple-native-geofencing/pull/15/commits/b13582e7fe1eb980f24f6060fa3c6d2459f559da

Balthazar33 commented 3 years ago

Hi @ShijeshiLeaf , can you confirm if this works ?