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" />
question from:
https://stackoverflow.com/questions/24681722/googleapiclient-onconnected-never-called-on-wearable-device 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…