Ich bin mit dem Problem konfrontiert in der Erstellung der Google API-Verbindung in Preference Fragment, ich erstellte GoogleApiClient Verbindung in einer Aktivität, aber in Fragment ist connectiong. Wenn das Fragment angezeigt wird, wird die Verbindung fehlgeschlagen angezeigt.Wie kann GoogleApiClient mit Google Play Services verbunden werden?
Der Code für GoogleApiClient ist
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Der obige Code innerhalb des onCreateView() Methode in einem Fragment angeordnet ist.
Die Verbindungs Rückrufe sind
@Override
public void onConnected(@Nullable Bundle bundle) {
Toast.makeText(getActivity(),"Connected Successfully",Toast.LENGTH_SHORT).show();
Log.e("SUCCESSFULL", "Connection successful");
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if(connectionResult.hasResolution())
{
try {
connectionResult.startResolutionForResult(getActivity(),RESOLVE_CONNECTION_REQUEST_CODE);
Toast.makeText(getActivity(),"Connected Failed",Toast.LENGTH_SHORT).show();
Log.e("SUCCESSFULL", "Connection Failed.....");
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(),getActivity(),0);
}
}
Wie dieses Problem zu lösen und die Google-API-Client-Verbindung in Fragmente machen.
Ich implementierte diese Funktionen, immer noch nicht behoben –
Veröffentlichen Sie Ihre Logcat-Fehler –