chris February 2016

Accessing app content provider from wearable

I am working on the udacity wearable course and unable to get my wearable emulator to send dataEvents to the wearable device.

On both the handheld and the wearable I have services that extend the WearableListenerService (WLS). The handheld version is currently started via a startService call in the activity, the wearable service is started in the watchface service also with startService, both services can be seen as started.

The device WLS successfully makes a call to the content provider and attempts at sending the data to the wearable, but putDataItem resultCallback is never called.

The wearable seems to be paired with my phone as I receive various notifications on it from my phone, so the setup is good. Both the handheld and wearable modules have the service added to the manifest with the required intent-filter, and with logging I can see they are both starting up as expected.

I am following the docs, but I must be missing something.

Thanks for any help.

Handheld service

public class WeatherDataService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = "HandheldService";
    private GoogleApiClient mGoogleClientApi;

    @Override
    public void onCreate() {
        super.onCreate();

        Log.d(TAG, "initializing");
        mGoogleClientApi = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
        mGoogleClientApi.connect();
    }

    @Override
    public void onPeerConnected(Node peer) {
        super.onPeerConnected(peer);
        Log.d(TAG, "onPeerConnected: " + peer.getDisplayName());
        

Answers


mahmoud moustafa February 2016

onDataChanged

doesn't call because you doesn't change any data that sent to wear every time(it's call only when the data really did change), try to send different data and it will work, and make sure to connect your mGoogleClientApi in onStrart();


chris February 2016

It turned out there was a couple things wrong with things.

The first was what @mahmoud mentioned, although I missed it the first time I read it, in that mGoogleClientApi.connect() needed to be called. When @mahmoud said connect to the client in onStart() I didn't read that as call the .connect() method.

The second things that was wrong was that the manifest package attributes did not match for each the modules. I thought they needed the same parent namespaces.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.sunshine.app">

Post Status

Asked in February 2016
Viewed 3,005 times
Voted 10
Answered 2 times

Search




Leave an answer