transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

Notifications not coming when application is in background or killed in Android #343

Closed dda-vasavi-yerapotula closed 7 years ago

dda-vasavi-yerapotula commented 7 years ago

Your Environment

Expected Behavior

Need to get notifications when the application is foreground, background or even it is killed

Actual Behavior

when the application gets killed or it is in background don't receive notifications when geofence is crossed in Android and works fine in Iphone

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

christocracy commented 7 years ago

The plugin isn't responsible for "notifications"

If you're performing stuff in a Javascript callback, the MainActivity (where your Javascript lives) is necessarily terminated when user terminates an Android applications. Only the plugin's native background-services remains alive and tracking (and optionally posting to your server if you configured an #url.

I suggest you switch to using server Push notifications. You might also explore the plugin's forceReload configuration params.

There's nothing the plugin can do to prevent the MainActivity (where your Javascript lives) from terminating.

dda-vasavi-yerapotula commented 7 years ago

Thanks for the response Chris. I am talking about the event geofence crossing also not getting fired. if that event fires our notification will work. we are able to get this working in Iphone and it is just an issue with android. does the foreReload option helps to resolve this issue?

christocracy commented 7 years ago

I do not see any reference to an issue about geofences being fired. Do you have a link to this thread?

dda-vasavi-yerapotula commented 7 years ago

i have attached my code and it has all events we are using and config file

christocracy commented 7 years ago

All your Javascript is terminated when app is terminated. None of your Javascript callbacks will execute.

Try using forceReloadOnGeofence: true

FYI: Do NOT execute any API method (aside from adding event-listeners until the callback to #configure executes:

// NO!  Do NOT execute #getCurrentPosition here!  Plugin is not ready to use until callback to #configure executes
$cordovaGeolocation.getCurrentPosition(options).then(function(position) {
                    var myLatitude = Math.round(position.coords.latitude * 10000000) / 10000000;
                    var myLongitude = Math.round(position.coords.longitude * 10000000) / 10000000;
                    if (config == undefined) {
                        config = $rootScope.appConfig;
                    }

                    var configuration = config.GeoFence;
                    BackgroundGeolocation.configure(configuration, function(state) {
                         /////////////////////////
                         // PLUGIN IS NOW READY TO USE.
                         //////////////////////////////////////////////////////////////////////

                    });                    
christocracy commented 7 years ago

Oh...hold on. You're using $cordovaGeolocation. Anyway, that plugin is completely unnecessary when using background-geolocation. In fact, in can cause permissions issues on iOS.

background-geolocation has its own perfectly ok #getCurrentPosition method.

dda-vasavi-yerapotula commented 7 years ago

Thanks Chris. I will follow up with my tesm

dda-vasavi-yerapotula commented 7 years ago

I have installed BG Geolocation app in my android phone and noticed the same problem. we are getting geofence exit message when application is in foreground. when I killed the application didn't get any notification. There is only message I always see on the lock screen that says location service activated. Any thoughts on this?

christocracy commented 7 years ago

Logs please. The sample app has an [email log] button in settings screen

dda-vasavi-yerapotula commented 7 years ago

I just got the below from the log

dda-vasavi-yerapotula commented 7 years ago

{ "isMoving": false, "distanceFilter": 20, "desiredAccuracy": 0, "locationUpdateInterval": 1000, "fastestLocationUpdateInterval": 1000, "geofenceProximityRadius": 250, "locationTimeout": 60, "activityRecognitionInterval": 1000, "minimumActivityRecognitionConfidence": 75, "triggerActivities": "in_vehicle, on_bicycle, running, walking, on_foot", "disableStopDetection": false, "stationaryRadius": 25, "stopTimeout": 0, "debug": true, "stopAfterElapsedMinutes": 0, "stopOnTerminate": false, "startOnBoot": true, "forceReloadOnLocationChange": false, "forceReloadOnMotionChange": false, "forceReloadOnGeofence": false, "forceReloadOnBoot": false, "forceReloadOnHeartbeat": false, "maxDaysToPersist": 1, "maxRecordsToPersist": -1, "url": "http:\/\/posttestserver.com\/post.php?dir=ionic-cordova-background-geolocation", "method": "POST", "autoSync": true, "autoSyncThreshold": 0, "batchSync": false, "params": { "device": { "available": true, "platform": "Android", "version": "7.0", "uuid": "5495e78c33a9ad13", "cordova": "5.2.2", "model": "SAMSUNG-SM-G930A", "manufacturer": "samsung", "isVirtual": false, "serial": "1a9b30d0" } }, "license": "", "configureInterval": 0, "maxBatchSize": -1, "heartbeatInterval": 60, "foregroundService": true, "notificationText": "Location Service activated", "deferTime": 0, "disableElasticity": false, "persist": true, "trackingMode": "location", "enabled": true, "schedulerEnabled": false }

christocracy commented 7 years ago

Those are not logs. That is a config object.

dda-vasavi-yerapotula commented 7 years ago

I clicked on send log button and selected email and this is what it send

christocracy commented 7 years ago

Did you build it yourself or install from play store?

-- Snet form Gmail Mobile

dda-vasavi-yerapotula commented 7 years ago

This is recently bought android last week and we bought this phone exclusively for geofence testing

dda-vasavi-yerapotula commented 7 years ago

From playstore

dda-vasavi-yerapotula commented 7 years ago

in Android

christocracy commented 7 years ago

I don't know how you managed to set this:

"geofenceProximityRadius": 250,

That shouldn't be possible from the UI. The minimum available selection is 1000.

Set that to 1000

dda-vasavi-yerapotula commented 7 years ago

I see many options in this geofenceproximityradius ( 0, 100, 250, 500, 1000, 2500, 5000, 10000) and I am able to change it

christocracy commented 7 years ago
dda-vasavi-yerapotula commented 7 years ago

wifi enabled and SIm card activated as I am getting geofence exit when application is in foreground. where do I see location services (set to high accuracy)?

christocracy commented 7 years ago

you installed this version from play store (see screenshot)?

https://play.google.com/store/apps/details?id=com.transistorsoft.backgroundgeolocation.ionic2

dda-vasavi-yerapotula commented 7 years ago

I actually installed the below one as we are using just Ionic (not ionic 2) https://play.google.com/store/apps/details?id=com.transistorsoft.background_geolocation.ionic

dda-vasavi-yerapotula commented 7 years ago

The first link didn't work with my phone and I have deleted it

dda-vasavi-yerapotula commented 7 years ago

The same version works perfectly in our mac and Iphone and it is only problem with new android phone

dda-vasavi-yerapotula commented 7 years ago

we are close to purchase this product just need to get it work when the app is killed in android

christocracy commented 7 years ago

Delete it. It doesn't matter if you're using Ionic 1. That old sample app is garbage and using a very OLD version of the plugin.

Only the Ionic 2 version uses the latest version of the plugin.

Install the Ionic 2 version.

dda-vasavi-yerapotula commented 7 years ago

but the new app I installed didn't work in my phone. i didn't get any message like geofence crossed and didn't even let me change settings

christocracy commented 7 years ago

Show me a screen shot of the settings screen of new app. How is it you can't change settings?

dda-vasavi-yerapotula commented 7 years ago

Ok I have installed new app and was able to change settings when I added fence. However I have to change it to trackingmode geofence and it changed it back to trackingmode location. let me drive tomorrow and i will let you know. Thanks for your time

christocracy commented 7 years ago

I just installed the Ionic 2 version from play store on 3 devices here with no issue.

dda-vasavi-yerapotula commented 7 years ago

But we are using Ionic 1 version. Do you have any detailed documentation on the flow of events that supports ionic 1 other than docs link in the website? App installs fine and I didn't find it working but will check again tomorrow morning

christocracy commented 7 years ago

and it changed it back to trackingmode location

This is merely a bug in the UI code for the Switch. The toggle handler is always calling bgGeo.start()

It should be checking trackingMode and:

if (trackingMode === 'location') {
  bgGeo.start();
} else {
  bgGeo.startGeofences();
}
christocracy commented 7 years ago

But we are using Ionic 1 version.

It doesn't matter. This is NOT an Ionic plugin -- it's a Cordova plugin. You can make your app with pure, vanilla Javascript -- what you build your UI with does not matter. Ionic is a UI FRAMEWORK. The plugin doesn't care about UI.

The plugin emits events only.

dda-vasavi-yerapotula commented 7 years ago

Is this the code base for the app you suggested just now

https://github.com/transistorsoft/cordova-background-geolocation-lt

christocracy commented 7 years ago

You should not use the SampleApp as a guide of how to use the plugin. The SampleApp has a whole bunch of complexity involving the Settings screen. Obviously you won't make an app with a settings screen around the plugin like that.

Using the plugin is all about listening to events.

// 1.  Listen to events
bgGeo.on('location', onLocation, onLocationFailure);
bgGeo.on('motionchange', onMotionChange);
bgGeo.on('providerchange', onProviderChange);
.
.
.
// 2. Configure the plugin.  
bgGeo.configure({
  desiredAccuracy: 0,   // <-- Config params
  distanceFilter: 50
}, function(state) {    // <-- Current state provided to #configure callback
  // 3.  Start tracking
  console.log('BackgroundGeolocation is configured and ready to use');
  if (!state.enabled) {
    bgGeo.start(function() {
      console.log('- BackgroundGeolocation tracking started');
    });
  }
});
christocracy commented 7 years ago

Is this the code base for the app you suggested just now https://github.com/transistorsoft/cordova-background-geolocation-lt

No, that is the plugin itself. In the README is a link to the Sample App

I suggest you carefully read all the README of the plugin. It's not that long.

dda-vasavi-yerapotula commented 7 years ago

I drove like 15 miles but didn't get any popup/notification from the BG Geo2 app. I also added fence with enter and exit options but didn't get any message and I do see the object changing in the map and it draws the route but no popup messages.

Moreover we created POC app to demonstrate this. i created apk file out of this code and tested in my samsung phone and notice the same issue. Can you please take a look at it and I am attaching my code here code.zip plugins_used

dda-vasavi-yerapotula commented 7 years ago

Also the log is here

{ "isMoving": false, "enabled": true, "odometer": 23783.475, "schedulerEnabled": false, "trackingMode": "location", "distanceFilter": 10, "desiredAccuracy": 0, "desiredOdometerAccuracy": 100, "locationUpdateInterval": 1000, "fastestLocationUpdateInterval": 10000, "locationTimeout": 60, "deferTime": 0, "disableElasticity": false, "activityRecognitionInterval": 10000, "minimumActivityRecognitionConfidence": 75, "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking", "disableStopDetection": false, "stationaryRadius": 25, "stopTimeout": 0, "url": "http:\/\/192.168.11.100:8080\/locations", "method": "POST", "autoSync": false, "autoSyncThreshold": 0, "batchSync": false, "maxBatchSize": -1, "params": { "device": { "model": "SAMSUNG-SM-G930A", "platform": "Android", "uuid": "5495e78c33a9ad13", "version": "7.0", "manufacturer": "samsung" } }, "headers": {}, "extras": {}, "httpRootProperty": "location", "locationTemplate": "", "geofenceTemplate": "", "persist": true, "maxDaysToPersist": 1, "maxRecordsToPersist": -1, "geofenceProximityRadius": 1000, "geofenceInitialTriggerEntry": true, "stopOnTerminate": false, "startOnBoot": true, "heartbeatInterval": -1, "foregroundService": true, "notificationTitle": "", "notificationText": "Location Service activated", "notificationColor": "", "notificationIcon": "", "forceReloadOnLocationChange": false, "forceReloadOnMotionChange": false, "forceReloadOnGeofence": false, "forceReloadOnBoot": false, "forceReloadOnHeartbeat": false, "forceReloadOnSchedule": false, "stopAfterElapsedMinutes": 0, "schedule": [], "configureUrl": "", "configureInterval": -1, "debug": true, "logLevel": 5, "logMaxDays": 3

christocracy commented 7 years ago

What radius of geofence are you creating?

On Thu, May 18, 2017 at 8:48 AM, dda-vasavi-yerapotula < notifications@github.com> wrote:

I drove like 15 miles but didn't get any popup/notification from the BG Geo2 app. I also added fence with enter and exit options but didn't get any message and I do see the object changing in the map and it draws the route but no popup messages.

Moreover we created POC app to demonstrate this. i created apk file out of this code and tested in my samsung phone and notice the same issue. Can you please take a look at it and I am attaching my code here code.zip https://github.com/transistorsoft/cordova-background-geolocation-lt/files/1010888/code.zip [image: plugins_used] https://cloud.githubusercontent.com/assets/21060971/26202825/c80660b0-3ba6-11e7-847f-45426842f144.PNG

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/343#issuecomment-302393732, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA6l3xYsNN0x8vfRbGUXAv__HHajFrGks5r7D43gaJpZM4NdKK- .

-- Chris Scott Transistor Software http://www.transistorsoft.com

dda-vasavi-yerapotula commented 7 years ago

POC project - 200 meters

dda-vasavi-yerapotula commented 7 years ago

have you tried the app in SAMSUNG-SM-G930A?

dda-vasavi-yerapotula commented 7 years ago

the details should be in attached code as well

christocracy commented 7 years ago

I develop strictly on Nexus devices because it's the flagship Android device, where APIs operate as documented.

This could be Samsung's Smart Manager messing things up.

However, I plan to purchase a Samsung G7 edge today.

dda-vasavi-yerapotula commented 7 years ago

Ok Chris. I am the technical lead for this project and need to give my analysis by tomorrow so that we can purchase this product. This is our ambitious project and my team is working on this for last 2 months :-) and also happy to see things working in IPhone. Are you going to check it in Samsung and let us know how it goes. Thanks for the prompt reply

christocracy commented 7 years ago

Here's my first boot of my SampleApp, a short 3km round-trip walk through 4 geofences. Looks good to me.

location markers off (showing geofence transitions)

dda-vasavi-yerapotula commented 7 years ago

Chris, what settings did you do to get these fences. I am trying now and cannot get it to work and I am using fake GPS free drive with BG geo app and see map is changing. Also did you get fence exited popup?

christocracy commented 7 years ago

Android Geofences don't fire with mocked locations, unfortunately. They only fire with real field-testing.

This above field-test was done with location tracking-mode (not geofences only). Mostly default settings.

{
    "isMoving": false,
    "enabled": true,
    "odometer": 2976.1577,
    "schedulerEnabled": false,
    "trackingMode": "location",
    "distanceFilter": 50,
    "desiredAccuracy": 0,
    "desiredOdometerAccuracy": 100,
    "locationUpdateInterval": 1000,
    "fastestLocationUpdateInterval": 10000,
    "locationTimeout": 60,
    "deferTime": 0,
    "disableElasticity": false,
    "activityRecognitionInterval": 10000,
    "minimumActivityRecognitionConfidence": 75,
    "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
    "disableStopDetection": false,
    "stationaryRadius": 25,
    "stopTimeout": 1,
    "url": "http:\/\/192.168.11.200:9000\/locations",
    "method": "POST",
    "autoSync": false,
    "autoSyncThreshold": 0,
    "batchSync": false,
    "maxBatchSize": -1,
    "params": {
        "device": {
            "model": "SAMSUNG-SM-G930A",
            "platform": "Android",
            "uuid": "ad94b1f488b08f2c",
            "version": "6.0.1",
            "manufacturer": "samsung",
            "framework": "Cordova"
        }
    },
    "headers": {},
    "extras": {},
    "httpRootProperty": "location",
    "locationTemplate": "",
    "geofenceTemplate": "",
    "persist": true,
    "maxDaysToPersist": 1,
    "maxRecordsToPersist": -1,
    "locationsOrderDirection": "ASC",
    "geofenceProximityRadius": 1000,
    "geofenceInitialTriggerEntry": true,
    "stopOnTerminate": false,
    "startOnBoot": true,
    "heartbeatInterval": -1,
    "foregroundService": true,
    "notificationTitle": "",
    "notificationText": "Location Service activated",
    "notificationColor": "",
    "notificationIcon": "",
    "forceReloadOnLocationChange": false,
    "forceReloadOnMotionChange": false,
    "forceReloadOnGeofence": false,
    "forceReloadOnBoot": false,
    "forceReloadOnHeartbeat": false,
    "forceReloadOnSchedule": false,
    "stopAfterElapsedMinutes": 0,
    "schedule": [],
    "configureUrl": "",
    "configureInterval": -1,
    "debug": true,
    "logLevel": 5,
    "logMaxDays": 3
}