Ich möchte den aktuellen Standort des Benutzers mithilfe von Play Service API abrufen. Aber immer seine Berufung onConnectionFailed()
Methode. Ich habe google-services.json Datei mit SHA-1-Schlüssel hinzugefügt. Aber es zeigt die Toast-Nachricht in onConnectionFailed() -Methode geschrieben. Wie kann ich es reparieren?Android - Fehler beim Herstellen einer Verbindung mit Google Play-Dienst
Hier ist mein Code -
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//setup GoogleApiClient
setupGoogleApiClient();
}
}
}
//setup GoogleApiClient object
private void setupGoogleApiClient() {
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
mGoogleApiClient.connect();
}
protected void onStart() {
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Toast.makeText(this, "Connected with google play service", Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionSuspended(int i) {
Toast.makeText(this, "Connection suspended with google play service", Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Toast.makeText(this, "Failed to connect with google play service", Toast.LENGTH_LONG).show();
}
}
bitte posten Sie Ihre Code –
Added der Code @NK mewara –
Sie sollten es selbst debuggen und sehen, was insbesondere 'ConnectionResult' gekommen sind. – Beloo