android - Accessing app content provider from wearable -


i working on udacity wearable course , unable wearable emulator send dataevents wearable device.

on both handheld , wearable have services extend wearablelistenerservice (wls). handheld version started via startservice call in activity, wearable service started in watchface service startservice, both services can seen started.

the device wls makes call content provider , attempts @ sending data wearable, putdataitem resultcallback never called.

the wearable seems paired phone receive various notifications on phone, setup good. both handheld , wearable modules have service added manifest required intent-filter, , logging can see both starting expected.

i following docs, must missing something.

thanks 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());          string[] temps = getcurrenttemps();          if (temps != null && temps.length == 2) {             log.d(tag, string.format("onpeerconnected: temps %s %s", temps[0], temps[1]));             notifywearables(mgoogleclientapi, temps[0], temps[1]);         }     }      private void notifywearables(googleapiclient client, string low, string high) {         log.d(tag, string.format("notifywearables: %s %s", low, high));         putdatamaprequest map = putdatamaprequest.create("/weather");         map.getdatamap().putstring("templow", low);         map.getdatamap().putstring("temphigh", high);          putdatarequest request = map.asputdatarequest();         wearable.dataapi.putdataitem(client, request).setresultcallback(new resultcallback<dataapi.dataitemresult>() {             @override             public void onresult(dataapi.dataitemresult result) {                 log.d(tag, string.format("onresult, %s", result.getstatus().getstatusmessage()));                 if (!result.getstatus().issuccess()) {                     log.d(tag, "onresult: failed send data");                 }             }         });        ... } 

wearable service

public class weatherdataservice extends wearablelistenerservice {      private static final string tag = "wearable:service";      @override     public void oncreate() {         super.oncreate();         // called         log.d(tag, "oncreate");     }      @override     public void ondatachanged(dataeventbuffer dataevents) {         // never makes here         log.d(tag, "ondatachanged: ");         (dataevent dataevent : dataevents) {             log.d(tag, "ondatachanged: " + dataevent.getdataitem().geturi().getpath());             if (dataevent.gettype() == dataevent.type_changed) {                 log.d(tag, "ondatachanged: type_changed");                 datamap datamap = datamapitem.fromdataitem(dataevent.getdataitem()).getdatamap();                 string path = dataevent.getdataitem().geturi().getpath();                 if (path.equals("/weather")) {                     log.d(tag, "ondatachanged: /weather");                     string templow = datamap.getstring("templow");                     string temphigh = datamap.getstring("temphigh");                      log.d(tag, "ondatachanged: " + templow + " " + temphigh);                 }             }         }     } } 

update

i missing mgoogleapiclient.connect() method call. putdataitem resultcallback being called, unforunately wearable device's ondatachanged event not being called.

ondatachanged 

doesn't call because doesn't change data sent wear every time(it's call when data did change), try send different data , work, , make sure connect mgoogleclientapi in onstrart();


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -