-
Notifications
You must be signed in to change notification settings - Fork 287
Add location snippet #652
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
Add location snippet #652
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
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.
Pull Request Overview
This PR adds a location detection snippet for Android Wear OS that demonstrates how to check if GPS is available on the device. The implementation follows the Android developer documentation for location detection in wearable apps.
- Adds a new LocationActivity with GPS availability checking functionality
- Creates a Compose UI that displays different messages based on GPS availability
- Registers the new activity in the Android manifest
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| wear/src/main/java/com/example/wear/snippets/location/LocationActivity.kt | New activity implementing GPS detection with Compose UI for displaying GPS availability status |
| wear/src/main/AndroidManifest.xml | Registers LocationActivity in the manifest with required configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
| else { |
Copilot
AI
Oct 9, 2025
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.
[nitpick] Use consistent formatting for the else clause. Either place 'else' on the same line as the closing brace or use braces for consistency with the if block.
| } | |
| else { | |
| } else { |
| } | ||
| // [END_EXCLUDE] | ||
| } | ||
| fun hasGps(): Boolean = |
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.
How do hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) and LocationManagerCompat.isLocationEnabled(locationManager) interoperate and is the latter relevant here?
For example, if the watch has GPS, but Location is disabled in the settings, do these return true and false respectively, and does that matter in this use case?
Or does FEATURE_LOCATION_GPS already take into account whether location is enabled by the location setting?
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.
Thanks for raising, it does NOT take into account whether location is enabled by the user setting. The current documentation doesn't mention it but I can add a new section and also mention this.
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.
rereading https://developer.android.com/training/wearables/apps/location-detection#DetectGPS, this is for GPS only and there is another section for requesting permissions and in https://developer.android.com/develop/sensors-and-location/location/retrieve-current?#last-known (which is linked from the same page) it explains what happens when location is tuned off in settings.
In summary: I think this snippet works as it is as this section is only focusing on gps, other sections of the same page cover the other cases.
This adds a snippet for https://developer.android.com/training/wearables/apps/location-detection.md#kotlin