Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25035] Android: App doesn't get the location when location permission is granted manually.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDone
Resolution Date2019-01-16T06:29:34.000+0000
Affected Version/sRelease 6.0.1, Release 6.1.1
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterJebun Naher
AssigneeUnknown
Created2017-07-31T08:43:10.000+0000
Updated2019-07-17T05:49:58.000+0000

Description

*Problem Description:* I'm using geolocation in my application. When I grant app location permission manually for my application it doesn't manage to show the location. I am using latest Ti SDK 6.1.1.GA, 6.0.1.GA. Using a Google Pixel running android 7 and a Sony C4 android 5.1 and it happens every time. It does not happen on the Samsung Galaxy though. *Steps to reproduce:* - Create a new Alloy project with the sample code below and launch the app, it will request for location permissions. If you grant the permission then the app will alert the coordinates. - But if you launch the app, then deny location permission - Then go to settings > apps and then grant the app location permissions - Now, when you launch the app again it does not manage to get the location. - If you then launch Google Maps or any other app that uses location and then go back into the app it suddenly works again. It's almost as if the app requires a different app to use the location before it can use it again. *Test Code:* index.js
$.index.open();

if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {

});
} else {
getGps();
}

function getGps() {

var coords = {};
var method = "";

var providerGps = Ti.Geolocation.Android.createLocationProvider({
name : Ti.Geolocation.PROVIDER_GPS,
minUpdateDistance : 0.0,
minUpdateTime : 0
});

Ti.Geolocation.Android.addLocationRule(Ti.Geolocation.Android.createLocationRule({
provider : Ti.Geolocation.PROVIDER_GPS,
accuracy : Alloy.CFG.accuracy,
maxAge : Alloy.CFG.maxAge,
minAge : Alloy.CFG.minAge
}));

Ti.Geolocation.Android.addLocationProvider(providerGps);
Ti.Geolocation.Android.manualMode = true;

Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
if ( typeof errorCallback != "undefined" && errorCallback != null) {
alert(e.error);
}
} else {
method = e.provider.name;
coords = e.coords;

alert(coords);

}
});

}
index.xml
<Alloy>

<Window>

</Window>

</Alloy>

Comments

  1. Enrico Toma 2017-11-09

    I have the same problem, but with automatic provider, in this configuration: - Ti SDK 6.3.0 - Android 6 - Galaxy S7 Following this step: - start device and activate localization. - open my app and after permission request, the properties Ti.Geolocation.locationServicesEnabled return false, then the Ti.Geolocation.getCurrentPosition fail. - close my app, open google maps. - return in my app and Ti.Geolocation.locationServicesEnabled return true, getCurrentPosition now is ok! - After disable Localization in the device and then re-enable. - return to app and Ti.Geolocation.locationServicesEnabled it's still false. On iOS the same code it's OK! I do not know how to do it. Hope you can help me Thanks
  2. Rodolfo Perottoni 2019-07-17

    I have the same issue, and it's been like this for ~3 years on one of my apps. I just had to accept that it wont work for some android users. The only way to make the GPS "kick in" is to start google maps and then come back to my app. So frustrating.

JSON Source