Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4982] Geolocation not working consistently on Android WebView (with suggested patch)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-10-12T22:08:20.000+0000
Affected Version/sRelease 2.0.2
Fix Version/sRelease 3.0.2, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21
ComponentsAndroid
Labelsandroid, api, geolocation, mobile, qe-port, webview
ReporterAllan Kim
AssigneeKarl Rowley
Created2011-08-03T18:33:39.000+0000
Updated2014-06-24T18:17:12.000+0000

Description

My experience shows that geolocation doesn't work consistently in an Android WebView, even when android.permission.ACCESS_FINE_LOCATION is added to tiapp.xml. To replicate: * Create simple app that loads a web page that uses geolocation APIs. In this case I used the KitchenSink app and changed the external URL in [web_views.js](https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/web_views.js) to a test page for W3C browser geolocation, http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html. * Add to tiapp.xml: **
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
* Save and build as usual. Install to Android device and to iOS device for comparison. * Verify that the permission privilege was added to build/android/AndroidManifest.xml. * Open KitchenSink on Android device and go to Base UI > Views > Web Views > External URL. Geolocation test fails. * Open KitchenSink in iOS device and repeat process. App requests location permission and test completes. Here is my suggested resolution to the problem: * Add the following to source code for TiWebChromeClient.java: **
public void onGeolocationPermissionsShowPrompt(String origin, android.webkit.GeolocationPermissions.Callback callback) {
     callback.invoke(origin, true, false);
}
* Build and update titanium-ui.jar. * Clean and build project and install new build to Android device. * Open KitchenSink on Android device and go to Base UI > Views > Web Views > External URL. Geolocation test succeeds!

Comments

  1. Paul Dowsett 2011-08-04

    Allan Thank you for raising this ticket. In order to progress it, please add the missing information in the format and places requested in the guidelines at [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist). Many thanks in advance
  2. Allan Kim 2011-08-04

    I've updated the ticket and description to follow the guidelines in the checklist. I've also added more details to replicate both the problem and the fix. Thank you!
  3. Paul Dowsett 2011-08-05

    Allan Many thanks for your contribution so far. Unfortunately this ticket still requires a few changes to be progressed. Would you add the code that you have actually tested, so that we can with some certainty replicate the issue? The simpler the code, the better, as explained in [Creating Good Use-cases](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-CreatingGoodUsecases). The environment field looks good. Just bear in mind that there are bugs in the Android 2.2.X emulator relating to webviews, so it is likely that they will only work correctly on a physical device. I have edited your ticket to use jira markup. Try to use markup in your future tickets. Thank you again
  4. Allan Kim 2011-08-10

    Pull request sent: branch TC-186-geolocationWebViewAndroid
  5. Paul Dowsett 2011-08-10

    Allan Thank you for the code. I will move this across to the correct project, but regrettably no action can be taken on your Pull Request until you have signed a CLA. Please see [Signing the Contributors License Agreement (CLA)](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-SigningtheContributorsLicenseAgreement%28CLA%29) for details. Please bear in mind the information I gave you in previous comments, about how to create a proper usecase. Thanks
  6. Paul Dowsett 2011-08-10

    By the way, I am very sorry, but I made a mistake previously. I meant to say that the Android 2.3.X emulator has webview issues, rather than 2.2.X. See [Android SDK / Target Android Platform](http://wiki.appcelerator.org/display/guides/Titanium+Compatibility+Matrix#TitaniumCompatibilityMatrix-AndroidSDK%2FTargetAndroidPlatform), which explains this.
  7. Paul Dowsett 2011-10-21

    Reassigning tickets, as per Tony Guntharp's request
  8. Karl Rowley 2012-10-10

    Pull request https://github.com/appcelerator/titanium_mobile/pull/3157
  9. Vishal Duggal 2013-01-16

    Backport task TIMOB-12300 backport PR https://github.com/appcelerator/titanium_mobile/pull/3719
  10. Paras Mishra 2013-01-24

    GeoLocation works fine. Verified on: LG device Android 2.2.2 SDK version: 3.1.0.v20130123144204,3.0.2.v20130122172624 CLI version : 3.0.23 OS : MAC OSX 10.7.5 XCode : 4.5.1

JSON Source