onDataChanged没有被调用

时间:2015-09-11 05:36:05

标签: android service wear-os

我正在开发用于佩戴和手持设备的演示应用程序。 当磨损开始时,它向掌上电脑发送请求并获得列表以及时间戳。当我们点击任何列表项时,它会再次向掌上电脑发送更改。 这完美地运作

但是我不想在点击设备列表时发送列表。 在设备活动线程

       class SendToDataLayerThread extends Thread {

    String path;
    DataMap dataMap;

    SendToDataLayerThread(String p,DataMap d){
        path = p;
        dataMap = d;
    }

    @Override
    public void run() {

         PutDataMapRequest putDMR= PutDataMapRequest.create(path);
                ArrayList<Job> arrlist=new ArrayList<>();
                ArrayList<String> staticArray=new ArrayList<>();
                mydb=new DBHelper(ListOfTaskActivity.this);
                arrlist.clear();
                arrlist = mydb.getAllCalls();

                if(arrlist.size()>0) {
                    for (int i = 0; i < arrlist.size(); i++) {
                        staticArray.add(arrlist.get(i).get_id()+"~"+arrlist.get(i).getJob_status()+"~"+arrlist.get(i).getJob_placename());

                    }
                }

                dataMap.putStringArrayList("CallArrayList", staticArray);

            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(wagoogleApiClient).await();
            for(Node node : nodes.getNodes()) {
                if(wagoogleApiClient.isConnected()){

                    dataMap.putLong("new_TimeStamp", new Date().getTime());
                    putDMR.getDataMap().putAll(dataMap);

                    PutDataRequest request = putDMR.asPutDataRequest();
                    Wearable.DataApi.putDataItem(googleApiClient,request);
                }
            }
       }
  }

这样可行,但onDataChanged的可穿戴服务从未调用

穿着服务

   public class WearableService extends WearableListenerService {
         @Override
public void onDataChanged(DataEventBuffer dataEvents) {
    super.onDataChanged(dataEvents);
     DataMap dataMap;
    try {
        for (DataEvent event : dataEvents) {
            Log.d(TAG, "in for DataEvent event : dataEvents");
            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String path = event.getDataItem().getUri().getPath();

                if(path.equals("/DataService_Path")) {
                   // change list
                 }
   }
 }

我被困在这里,谢谢你提前帮助

1 个答案:

答案 0 :(得分:0)

您是否已连接到服务中的googleclientapi?

mGoogleApiClient =新的GoogleApiClient.Builder(上下文)                     .addApi(Wearable.API)                     .addConnectionCallbacks(本)                     。建立(); mGoogleApiClient.connect()

同时查看此帖:

WearableListenerService, onDataChanged() is not called