-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Location access via JavaScript #28
base: main
Are you sure you want to change the base?
Conversation
override fun createWebChromeClient(): TurboWebChromeClient { | ||
return object : TurboWebChromeClient(session) { | ||
override fun onGeolocationPermissionsShowPrompt( | ||
origin: String?, | ||
callback: GeolocationPermissions.Callback? | ||
) { | ||
if (ContextCompat.checkSelfPermission( | ||
requireContext(), | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
) != PackageManager.PERMISSION_GRANTED | ||
) { | ||
permissionLauncher.launch( | ||
Manifest.permission.ACCESS_FINE_LOCATION | ||
) | ||
} else { | ||
callback?.invoke(origin, true, false) | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would live in TurboWebChromeClient
. But I wasn't sure how to get a reference for the permission launcher.
private val permissionLauncher = registerForActivityResult( | ||
ActivityResultContracts.RequestPermission() | ||
) { isGranted -> | ||
if (isGranted) refresh() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal world this would refresh and re-request the user's location. But I don't think that is possible with a web view.
* main: Present better looking Material dialogs for WebView alert and confirm dialogs Allow camera capture by default if the accept type explicitly allows images
* main: (63 commits) Update to the latest gradle plugin Include Turbo Native Android in the user agent substring for backwards compatibilty with existing apps Change Turbo Native to Hotwire Native in user agent. Update HotwireNavigation.kt Remove old docs Update README.md Revert "Add repositories to each build script" Add repositories to each build script Disable the gradle configuration cache due to incompatibility with the signing plugin Add the signing plugin Add Sonatype (Maven Central) publishing support Readme updates Add publishing build script for the navigation-fragments module Remove Strada references Update demo site url Update android plugin dependencies Update CI workflow actions Update logo filename Update raster launcher icon Update vector launcher icon ... # Conflicts: # demo/src/main/kotlin/dev/hotwire/demo/features/web/WebFragment.kt
… the HotwireWebChromeClient if the app has declared location permission(s) are declared in the app manifest.
…e permission with the WebView
This PR configures the web view and
WebFragment
to access the user's location via JavaScript.The first time the user's location is accessed the following appears:
If accepted,
WebFragment
reloads the page. When the location is accessed a second time the following appears:If the permissions in the manifest file are commented out the following appears when accessing the user's location:
Note that this only works against HTTPS websites, so you will need to tunnel via ngrok for Chrome to expose the user's location.
The following Stimulus controller was used to test the location access: