Browse files

Support geolocation in android webview

Makes sure request for geolocation use in the webview is handled.
This solves issue #7609

Currently use of geolocation in webview fails silently, as the permission request is never received by the native app.

**Test plan (required)**

1. Create new project with webview
2. Add javascript for geolocation:
navigator.geolocation.getCurrentPosition(function (position) {
  console.log('success', position)
}, function (error) {
  console.log('could not determine position', error)
3. Run code and assert geolocation permission is requested, resulting in success (or error) callback being called
Closes #8305

Differential Revision: D3592887

fbshipit-source-id: 84fe2383fba8873431c5e89d154c0a4fd58ffb70
  • Loading branch information...
1 parent 654e4be commit b7bf24bc7f4d62dd0f4417b45cbf4423fe664aa7 @jvassbo jvassbo committed with Facebook Github Bot 9 Jul 20, 2016
@@ -18,6 +18,7 @@
import android.os.Build;
import android.text.TextUtils;
+import android.webkit.GeolocationPermissions;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
@@ -259,7 +260,12 @@ public String getName() {
protected WebView createViewInstance(ThemedReactContext reactContext) {
ReactWebView webView = new ReactWebView(reactContext);
- webView.setWebChromeClient(new WebChromeClient());
+ webView.setWebChromeClient(new WebChromeClient() {
+ @Override
+ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
+ callback.invoke(origin, true, false);
+ }
+ });

0 comments on commit b7bf24b

Please sign in to comment.