Skip to content

Commit 13c9ac3

Browse files
committed
Enable geolocation on Android
1 parent 5d5316f commit 13c9ac3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
9797
Map<String, String> headers = call.argument("headers");
9898
boolean scrollBar = call.argument("scrollBar");
9999
boolean allowFileURLs = call.argument("allowFileURLs");
100+
boolean geolocationEnabled = call.argument("geolocationEnabled");
100101

101102
if (webViewManager == null || webViewManager.closed == true) {
102103
webViewManager = new WebviewManager(activity);
@@ -118,7 +119,8 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
118119
scrollBar,
119120
supportMultipleWindows,
120121
appCacheEnabled,
121-
allowFileURLs
122+
allowFileURLs,
123+
geolocationEnabled
122124
);
123125
result.success(null);
124126
}

android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void openUrl(
204204
boolean scrollBar,
205205
boolean supportMultipleWindows,
206206
boolean appCacheEnabled,
207-
boolean allowFileURLs
207+
boolean allowFileURLs,
208+
boolean geolocationEnabled
208209
) {
209210
webView.getSettings().setJavaScriptEnabled(withJavascript);
210211
webView.getSettings().setBuiltInZoomControls(withZoom);
@@ -219,6 +220,16 @@ void openUrl(
219220
webView.getSettings().setAllowFileAccessFromFileURLs(allowFileURLs);
220221
webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs);
221222

223+
if (geolocationEnabled) {
224+
webView.getSettings().setGeolocationEnabled(true);
225+
webView.setWebChromeClient(new WebChromeClient() {
226+
@Override
227+
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
228+
callback.invoke(origin, true, false);
229+
}
230+
});
231+
}
232+
222233
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
223234
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
224235
}

0 commit comments

Comments
 (0)