I am making an Android Wear Watch Face and I need to show user current location.
I was followed tutorial on Dev site, but I can't get it to work. The code never goes to "onLocationChanged" listener.
Device is Huawei watch, and it is connected to mobile with WiFi and Location on.
Permissions are on (I have runtime permission request). Here is the code:
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
build.gradle (Module.wear)
compile 'com.google.android.gms:play-services-location:8.4.0'
AnalogFaceService.java
googleApiClient = new GoogleApiClient.Builder(AnalogFaceService.this)
.addApi(LocationServices.API)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
@Override
public void onConnected(@Nullable Bundle bundle)
{
LocationRequest locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
.setInterval(TimeUnit.SECONDS.toMillis(2))
.setFastestInterval(TimeUnit.SECONDS.toMillis(2))
.setSmallestDisplacement(2);
if
(
(
ActivityCompat.checkSelfPermission(AnalogFaceService.this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
) && (
ActivityCompat.checkSelfPermission(AnalogFaceService.this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
)
) {
return;
}
LocationServices.FusedLocationApi
.requestLocationUpdates(googleApiClient, locationRequest, onLocationChangedListener)
.setResultCallback(locationCallback);
}
private final LocationListener onLocationChangedListener = new LocationListener()
{
@Override
public void onLocationChanged(Location location)
{
Log.v("LOCATION_TEST", location.getLatitude() + " :::: " + location.getLongitude());
getSunriseAndSunset(location);
addLocationEntry(location.getLatitude(), location.getLongitude());
}
};