This is a follow up question to... Android Wear Bundled Notifications and Background Images
I'd like to create a Android Wear GridViewPager layout that get's created when a new push notification comes in.
Below is my code that initializes a GoogleApiClient connection when a new message comes in so I can then send data to the wear app which then creates the GridView Pager.
My problem is that the GoogleApiClient never gets a connection. I've successfully run the SynchonizedNotifications sample app in the sdk folder so I know my device and watch are paired correctly.
Below is current code...
public class GCMIntentService extends IntentService implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
@Override
protected void onHandleIntent(Context context, Intent intent) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS);
// Extract the payload from the message
Bundle extras = intent.getExtras();
if (this.mGoogleApiClient.isConnected()) {
// sending a simple message works
MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient,
node.getId(), "path", null).await();
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(Constants.BOTH_PATH);
putDataMapRequest.getDataMap().putString(Constants.KEY_CONTENT, "content");
putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, "title");
PutDataRequest request = putDataMapRequest.asPutDataRequest();
// push data to wear app here
Wearable.DataApi.putDataItem(mGoogleApiClient, request)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(DataApi.DataItemResult dataItemResult) {
if (!dataItemResult.getStatus().isSuccess()) {
Log.e(TAG, "Failed to set the data, status: " + dataItemResult.getStatus().getStatusCode());
}else{
// get here, but no message received from wear
Log.i(TAG,"SUCCESSFUL RESPONSE RECEIVED FROM WEAR");
}
mGoogleApiClient.disconnect();
}
});
} else {
Log.e(TAG, "no Google API Client connection");
}
}
}