Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleApiClient onConnected never called on Wearable device

I have a wearable device that I'm trying to connect to the GoogleApiClient but the callbacks are never called (onConnected, onConnectionSuspended or onConnectionFailed). Everything else is working fine, the DataLayerListenerService is able to receive messages from the handheld and the onPeerConnected is being called when it connects. I've tried in on both the emulator and a Samsung Gear Live device. This is the code that I have in the Activity where I'm trying to connect to the GoogleApiClient.

public class WearReaderActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {     public static final String CONTENT_EXTRA = "contentExtra";     private String LOG_TAG = WearReaderActivity.class.getSimpleName();      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.reader);         mGoogleApiClient = new GoogleApiClient.Builder(this)                 .addApi(Wearable.API)                 .addConnectionCallbacks(this)                 .addOnConnectionFailedListener(this)                 .build();     }      private GoogleApiClient mGoogleApiClient;      @Override     protected void onStart() {         super.onStart();         Log.e("Connected?", String.valueOf(mGoogleApiClient.isConnected()));         //new Thread(new GetContent()).start();     }      @Override     public void onConnected(Bundle bundle) {         Log.d("Connected", "Connected");         new Thread(new GetContent()).start();     }      @Override     public void onConnectionSuspended(int i) {         Log.d("Connection suspened", "Connection suspended");     }      @Override     public void onConnectionFailed(ConnectionResult connectionResult) {         Log.d("Connection suspened", "Connection suspended");     } ... } 

Not sure if it'll help but this is my Manifest for the Wearable app

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"           package="my.packagename">     <application         android:allowBackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@android:style/Theme.DeviceDefault" >         <meta-data             android:name="com.google.android.gms.version"             android:value="@integer/google_play_services_version" />      <activity         android:name=".WearReaderActivity"         android:label="Reading" >         <intent-filter>            <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>     </activity>  <meta-data android:name="com.google.android.gms.version"        android:value="@integer/google_play_services_version" />      <service         android:name=".DataLayerListenerService" >         <intent-filter>             <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />         </intent-filter>     </service>  </application> 

Any ideas?

EDIT: Added the following to the wearable manifest, still not working though

<meta-data android:name="com.google.android.gms.version"            android:value="@integer/google_play_services_version" /> 
like image 417
odiggity Avatar asked Jul 10 '14 16:07

odiggity


2 Answers

Oh wow, the answer is embarrassingly simple. I missed the part where in onStart() you need to call mGoogleApiClient.connect().

like image 57
odiggity Avatar answered Oct 24 '22 21:10

odiggity


You can call the connect and disconnect manually in the onStart and onStop lifecycle methods, or you can use the enableAutoManage feature.

mCredentialsApiClient = new GoogleApiClient.Builder(this)             .addConnectionCallbacks(this)             .enableAutoManage(this, this)             .addApi(Auth.CREDENTIALS_API)             .build(); 
like image 38
Imre Avatar answered Oct 24 '22 23:10

Imre