问题
I have connected my Samsung GEAR Live
to my Android device through bluetooth
. I have active internet connection & GPS
enabled on my Android device.
Now, I am trying to get the GPS location from Wearable App
.
LocationManager locationManager = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
// getting GPS status
boolean isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
boolean isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isGPSEnabled == false && isNetworkEnabled == false) {
location = null;
} else if (isGPSEnabled) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
if (isNetworkEnabled && location == null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
But, isGPSEnabled
and isNetworkEnabled
both are returning false.
What could be the reason? How to get the location from Wearable App
?
回答1:
Android Wear is a normal Android device. These API returns false because your Android Wear device doesn't have GPS or network connection.
You can implement your own "GPS provider" that sends gps position obtained by a phone to your to Wearable app.
You can use Google Play services Location API to obtain GPS position because they have made it work automatically on Wear. Here is a post on Google+ that confirms this: https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx
To implements Google Play services please follow these tutorials:
Retrieving the Current Location:
https://developer.android.com/training/location/retrieve-current.html
Receiving Location Updates:
https://developer.android.com/training/location/receive-location-updates.html
Please notice that it should work with any of Location API so you can also use APIs like ActivityRecognitionApi
, GeofencingApi
etc.
https://developer.android.com/reference/com/google/android/gms/location/package-summary.html
来源:https://stackoverflow.com/questions/24848970/is-it-possible-to-get-gps-location-from-android-wear-sdk