I'm trying to send a String array from my phone to my clothes, I created a service on my phone that should send data using this code:
public class SendDataService extends Service { private static final String TAG = "SendDataService"; @Override public void onCreate(){ GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.d(TAG, "onConnected: " + connectionHint);
and from the clock I try to get it in my main action using this code:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_agenda_wear); this.context = this; 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 } @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); } }) .addApi(Wearable.API) .build(); mGoogleApiClient.connect(); PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(0)); // This should read the correct value. AgendaWear.this.eventString = dataMapItem.getDataMap().getStringArray("events"); } dataItems.release(); } }); mGoogleApiClient.disconnect(); final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { if (AgendaWear.this.eventString == null){ Toast.makeText(AgendaWear.this, "No data",Toast.LENGTH_LONG).show(); AgendaWear.this.eventString = new String[0]; } AgendaWear.listItems = eventArray(AgendaWear.this.eventString); mListView = (WearableListView) stub.findViewById(R.id.listView); mListView.setAdapter(new MyAdapter(AgendaWear.this)); mListView.setClickListener(AgendaWear.this); } }); }
But unfortunately, I always get toast without data, and I'm a little stuck here, I have the line <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> both for wearing and for the mobile part of my application, but I do not seem to receive any data. Thank you in advance for your help.
source share