Ich entwickle eine Android-App für eine Smartwatch, die gekauft wurde und in China läuft.GPS-Standort in meinem Android finden Wearable in China
Mein Ziel ist es, die GPS-Position des Geräts und seine Bewegung zu verfolgen, aber ich kann nicht finden, wie es funktioniert.
Derzeit entwickle ich für API 21 und ich bin mit der folgenden Bibliothek von Google Play-Diensten, wie es derjenige von Wearables in China verwendet wird: com.google.android.gms:play-services-wearable:7.8.87
Der Code, den ich verwende ist die folgende:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_on_route);
locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(UPDATE_INTERVAL_MS)
.setFastestInterval(FASTEST_INTERVAL_MS);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addApi(Wearable.API) // used for data layer API
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
startTravelTime = System.currentTimeMillis();
if (!hasGps()) {
Log.d(TAG, "This hardware doesn't have GPS.");
}
}
private boolean hasGps() {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
Log.i("Connected!!!", "WERE CONNECTED");
}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
mGoogleApiClient.disconnect();
System.out.println("onstop");
}
@Override
protected void onResume() {
super.onResume();
if(!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
@Override
protected void onPause() {
super.onPause();
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, OnRouteActivity.this);
}
mGoogleApiClient.disconnect();
}
@Override
public void onConnected(Bundle bundle) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.getStatus().isSuccess()) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Successfully requested location updates");
}
} else {
Log.e(TAG,
"Failed in requesting location updates, "
+ "status code: "
+ status.getStatusCode()
+ ", message: "
+ status.getStatusMessage());
}
}
});
}
@Override
public void onLocationChanged(Location location){
// Display the latitude and longitude in the UI
mTextView = (TextView) findViewById(R.id.location);
mTextView.setText("Latitude: " + String.valueOf(location.getLatitude()) + "\nLongitude: " + String.valueOf(location.getLongitude()));
Toast.makeText(getBaseContext(), "Latitude: " + String.valueOf(location.getLatitude()) + "\nLongitude: " + String.valueOf(location.getLongitude()), Toast.LENGTH_LONG).show();
}
ich hoffe jemand kann mir helfen, mit dieser :)
Das Problem zu finden ist, wenn ich die Version von Google-Services I Play erhalten Sie den folgenden Fehler: _Google Play-Dienste veraltet. Benötigt 10298000 aber gefunden 7571430_ Kennen Sie eine niedrigere Version, die mit meiner Uhr funktionieren könnte? – cabanapi
Ich benutze den Emulator (Teil der Canary 9 Build für Android Studio 3.0), um meine Apps zu testen. Bis jetzt hatte ich keine Probleme. Ich weiß nicht, ob Sie eine niedrigere Version verwenden können, aber basierend auf der Dokumentation klingt es nicht so. Vielleicht ist deine Uhr zu alt und nicht unterstützt? – TofferJ
Ich dachte über diese Möglichkeit nach :(Ich werde meinen Code mit dem Emulator testen, um zu sehen, ob es dort funktioniert und wenn es ist, wird das Problem definitiv die Version der Uhr sein. Danke! – cabanapi