Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.10.4

* Adds a README section about enabling geolocation.

## 4.10.3

* Updates Java compatibility version to 17.
Expand Down
23 changes: 23 additions & 0 deletions packages/webview_flutter/webview_flutter_android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ androidController.setCustomWidgetCallbacks(
);
```

## Geolocation

By default, WebView does not allow geolocation requests. To allow them, call
`setGeolocationPermissionsPromptCallbacks` on the `AndroidWebViewController` to
configure a prompt handler. For example, to unconditionally allow all requests:

<?code-excerpt "example/lib/readme_excerpts.dart (geolocation_example)"?>
```dart
await androidController.setGeolocationPermissionsPromptCallbacks(
onShowPrompt: (GeolocationPermissionsRequestParams request) async {
return const GeolocationPermissionsResponse(allow: true, retain: true);
},
);
```

**Important:** Geolocation requests should only be allowed unconditionally if
the web view content is restricted to domains you control or trust. If you are
showing untrusted content, the `onShowPrompt` implementation should request
permission from the user before responding.

Your application must have geolocation permissions granted in order for the
WebView to have access to geolocation.
Comment on lines +129 to +130

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation mentions that the application needs geolocation permissions, but it doesn't specify which permissions are required or how to add them. This could be confusing for developers and lead to extra research time.

To make the documentation more helpful, I suggest adding the specific permissions required in AndroidManifest.xml and mentioning the need for runtime permission requests. This will provide a more complete guide for enabling geolocation.

Suggested change
Your application must have geolocation permissions granted in order for the
WebView to have access to geolocation.
Your application must have geolocation permissions granted for the
WebView to have access to geolocation. This requires adding the following
permissions to your AndroidManifest.xml file, located in
`<project>/android/app/src/main/AndroidManifest.xml`:
```xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

You may also need to request permissions at runtime. See the documentation for
the permission_handler package for details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had considered this, but explicitly do not want us to be in the business of documenting exactly what the interaction between the system WebView and the Android permission system are, and maintaining that as they inevitably change.


## Contributing

For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,22 @@ Future<void> enablePaymentRequest() async {
}
// #enddocregion payment_request_example
}

/// Example function for README demonstration of geolocation permissions for
/// a use case where the content is always trusted (for example, it only shows
/// content from a domain controlled by the app developer) and geolocation
/// should always be allowed.
Future<void> setGeolocationPermissionsPrompt() async {
final PlatformWebViewController controller = PlatformWebViewController(
AndroidWebViewControllerCreationParams(),
);
final AndroidWebViewController androidController =
controller as AndroidWebViewController;
// #docregion geolocation_example
await androidController.setGeolocationPermissionsPromptCallbacks(
onShowPrompt: (GeolocationPermissionsRequestParams request) async {
return const GeolocationPermissionsResponse(allow: true, retain: true);
},
);
// #enddocregion geolocation_example
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_android
description: A Flutter plugin that provides a WebView widget on Android.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 4.10.3
version: 4.10.4

environment:
sdk: ^3.9.0
Expand Down