Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25974] Android: Ti.Geolocation updates rarely on Android 8.0 while app is backgrounded

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2018-06-06T01:31:05.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.3.0
ComponentsAndroid
Labelsandroid, location, service
ReporterJebun Naher
AssigneeJoshua Quick
Created2018-04-18T12:14:29.000+0000
Updated2018-06-19T21:57:15.000+0000

Description

*Issue Overview:* I need my app to get the location every 5 seconds. It seems when the phone becomes 'locked' and the screen goes off, the location updates very rarely. If I request the location the timestamp of the location object doesn't change. I've tried manual mode but I get the same result. How can I get the realtime location when the phone is on or off? *Reproduction:* Run the test code Check the log and observe that the timestamp never changes. So it seems the geolocation doens't expire after 10 seconds. *index.js*
function getLocation() {
    Ti.Geolocation.addEventListener('location', function(e) {
        alert(JSON.stringify(e, null, 2));
    });
}

$.win.addEventListener('open', function() {
    if (Ti.Geolocation.hasLocationPermissions()){
        getLocation();
     } else {
        Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
            if (e.success) {
                getLocation();
            } else {
                alert('could not obtain location permissions');
            }
        });
    }
});

Ti.Geolocation.Android.manualMode = true;
var gpsProvider = Ti.Geolocation.Android.createLocationProvider({
name: Ti.Geolocation.PROVIDER_GPS,
minUpdateTime: 5,
minUpdateDistance: 1
});

var gpsRule = Ti.Geolocation.Android.createLocationRule({
accuracy: 100,
maxAge: 10000,
});

Ti.Geolocation.Android.addLocationRule(gpsRule);
setInterval(function(){
Titanium.Geolocation.getCurrentPosition(function(e){
var accuracy = e.coords.accuracy;
var timestamp = e.coords.timestamp;
var report = 'geo time: ' + new Date(timestamp) + ', accuracy: ' + accuracy;
//$.label.text = report;
console.log(report);	
});
},5000);
*Output*
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492
[INFO] : geo time: Wed Apr 18 2018 11:06:28 GMT+0100 (BST), accuracy: 18.344999313354492

Comments

  1. Joshua Quick 2018-05-26

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10076 Solution is to use an Android "foreground" service.
  2. Lokesh Choudhary 2018-06-19

    Verified the fix in SDK 7.3.0.v20180618182516. Closing.

JSON Source