Android wear app can't connect to google api services

后端 未结 2 381
别跟我提以往
别跟我提以往 2021-01-16 23:15

I\'m trying to set up a connection between Android Wear and an Android phone. The googleApiClient fails to connect, and returns a SERVICE_VERSION_UPDATE_REQUIRED status code

相关标签:
2条回答
  • 2021-01-16 23:43

    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

    0 讨论(0)
  • 2021-01-16 23:44

    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();
    }
    
    0 讨论(0)
提交回复
热议问题