Android GoogleApiClient永远不会连接或失败。什么也没做

时间:2017-05-28 18:15:10

标签: android google-api-client

尝试连接到GoogleApiClient,但遇到其中一种情况,而不是发生错误,根本没有任何事情发生。

public class Locator
        extends Activity
        implements
        LocationListener, 
        GoogleApiClient.ConnectionCallbacks, 
        GoogleApiClient.OnConnectionFailedListener {

    GoogleApiClient mGoogleApiClient;
    Location        mLastLocation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_atmbranch_locator);

        // Create an instance of GoogleAPIClient.
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();
        }
    }
    @Override
    protected void onStart(){
        mGoogleApiClient.connect();
        super.onStart();
        // Note: This does get called
    }
    @Override
    protected void onStop() {
        mGoogleApiClient.disconnect();
        super.onStop();
    }
    @Override
    public void onLocationChanged(Location location) {
        // This never gets called
    }
    @Override
    public void onConnected(@Nullable Bundle bundle) {
        // This never gets called
    }
    @Override
    public void onConnectionSuspended(int i) {
        // This never gets called
    }
    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        // This never gets called
    }
}

0 个答案:

没有答案