我跟随本教程,尝试让我的磨损应用和移动应用进行通信。
https://www.binpress.com/tutorial/a-guide-to-the-android-wear-message-api/152
我认为必须省略解决方案的某些部分,因为我一直在崩溃:
E/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: com.webiphany.wearsync, PID: 27299
java.lang.NullPointerException: GoogleApiClient must not be null
at com.google.android.gms.common.internal.zzac.zzb(Unknown Source)
at com.google.android.gms.internal.zzzv$zza.<init>(Unknown Source)
at com.google.android.gms.wearable.internal.zzm.<init>(Unknown Source)
at com.google.android.gms.wearable.internal.zzcb$2.<init>(Unknown Source)
at com.google.android.gms.wearable.internal.zzcb.getConnectedNodes(Unknown Source)
at com.webiphany.wearsync.MainActivity$2.run(MainActivity.java:61)
at java.lang.Thread.run(Thread.java:761)
我的服装和移动应用程序在这里:
https://github.com/xrd/WearSync
磨损应用程序的相关连接代码如下:
private void initGoogleApiClient() {
mApiClient = new GoogleApiClient.Builder( this )
.addApi( Wearable.API )
.build();
mApiClient.connect();
}
Android应用程序的连接代码在这里:
private void setupDataLayer() {
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected: " + connectionHint);
// Now you can use the Data Layer API
sendMessage( START_ACTIVITY, "" );
}
@Override
public void onConnectionSuspended(int cause) {
Log.d(TAG, "onConnectionSuspended: " + cause);
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.d(TAG, "onConnectionFailed: " + result);
}
})
// Request access only to the Wearable API
.addApi(Wearable.API)
.build();
}
有关我做错的任何建议吗?