Android wear app can't connect to google api services

℡╲_俬逩灬. 提交于 2019-12-01 14:46:59

Android Wear requires you have Google Play services version >= 5.0.89 installed on your phone

You can check your version and update the Play Services APK here: https://play.google.com/store/apps/details?id=com.google.android.gms&hl=en

Also Useful:

Important: Because it is hard to anticipate the state of each device, you must always check for a compatible Google Play services APK before you access Google Play services features. For many apps, the best time to check is during the onResume() method of the main activity.

Code to check if Play Services is available (on your phone):

// ########################################################################
// Check if Google Play Services is installed. If not show error dialog.
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if( ConnectionResult.SUCCESS == result ){
    mGoogleApiClient.connect();
    loadingTextView.setText("Connecting to Wear...");
}
else {
    // Show appropriate dialog
    Dialog d = GooglePlayServicesUtil.getErrorDialog(result, this, 0);
    d.show();
}

More details here:

https://developer.android.com/google/play-services/setup.html#ensure

Looks like putting the googleClient.connect() on onStart() solves the issue:

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

    // Build a new GoogleApiClient
    checkIfGoogleApiClientExists();
    googleClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}

@Override
protected void onStart() {
    Log.i(LOG_TAG,"entered onStart");
    super.onStart();
    googleClient.connect();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!