[TIMOB-4982] Geolocation not working consistently on Android WebView (with suggested patch)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-10-12T22:08:20.000+0000 |
Affected Version/s | Release 2.0.2 |
Fix Version/s | Release 3.0.2, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21 |
Components | Android |
Labels | android, api, geolocation, mobile, qe-port, webview |
Reporter | Allan Kim |
Assignee | Karl Rowley |
Created | 2011-08-03T18:33:39.000+0000 |
Updated | 2014-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!
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
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!
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
Pull request sent: branch TC-186-geolocationWebViewAndroid
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
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.
Reassigning tickets, as per Tony Guntharp's request
Pull request https://github.com/appcelerator/titanium_mobile/pull/3157
Backport task TIMOB-12300 backport PR https://github.com/appcelerator/titanium_mobile/pull/3719
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