Skip to content Skip to sidebar Skip to footer

Android Wear Ondatachanged Isn't Called

I downloaded a ready phone app and trying to implement a watchface for my android wear project. The goal is to pass temperature information from phone to the wear device and have i

Solution 1:

Sent you a pull request on GitHub with corrections. Seems like you just forget to connect your google client :)

mGoogleApiClient.connect();

And some additional small changes in your code (some refactoring).

Solution 2:

You have to create a BroadcastReceiver in your WatchFace class, and register it under the registerReceiver() method.

Create the BroadcastReceiver first, for example:

finalBroadcastReceivermWeatherReceiver=newBroadcastReceiver() {
        @OverridepublicvoidonReceive(Context context, Intent intent) {
            // Get the data from the intent here // and set the variables you're going to use in your onDraw method
        }
};

Then register the receiver, for example:

privatevoidregisterReceiver() {

         //This is where you have the default watch face receiver // Register your new weather receiver
        IntentFilter weatherFilter = new IntentFilter("ACTION_WEATHER_CHANGED");
        SunshineWatchFace.this.registerReceiver(mWeatherReceiver, weatherFilter );
    }

Finally, on the onDataChanged of you WatchListenerService, send the data via Intent to the BroadcastReceiver. For example:

@OverridepublicvoidonDataChanged(DataEventBuffer dataEvents) {

           // Check the data typeif (event.getType() == DataEvent.TYPE_CHANGED) {
                    // Get the data map
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                    Log.i(LOG_TAG, "DataMap received on watch: " + dataMap);

                    // Get the data map itemsStringsunshine_temperature_high= dataMap.getString("sunshine_temperature_high");
                    Stringsunshine_temperature_low= dataMap.getString("sunshine_temperature_low");

                    // Create the intentIntentsend_weather=newIntent("ACTION_WEATHER_CHANGED");
                    send_weather.putExtra("sunshine_temperature_high", sunshine_temperature_high);
                    send_weather.putExtra("sunshine_temperature_low", sunshine_temperature_low);
                    // Broadcast it
                    sendBroadcast(send_weather);

                }
                elseif (event.getType() == DataEvent.TYPE_DELETED) {
                    // DataItem deleted
                }
   }

Solution 3:

Did you add your CanvasWatchFaceService as listener to data changed events? In onConnected make sure you call:

Wearable.DataApi.addListener(mGoogleApiClient, this);

Solution 4:

Your should always check if:

  1. Your mobile is connected to the wear
  2. The package names are the same
  3. You are using the same Google Play service version on both apps
  4. You are signing both mobile and wear apps using the same keystore

I got stuck on GoUbiquitous for 10 days until I figure out the last one :-\

Post a Comment for "Android Wear Ondatachanged Isn't Called"