本文介绍了onDataChanged 没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于穿戴和手持设备的演示应用程序.当磨损开始时,它会向手持设备发送请求并获取带有时间戳的列表.当我们单击任何列表项时,它会再次将更改发送到掌上电脑.这很完美

I am developing demo application for wear and handheld.When wear starts it sends request to handheld and get list along with time stamp. and while we click on any list item, it sends changes to handheld again.This works perfectly

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

But not i want to sends list while on click of device list is performs.in device activity thread

       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 从未调用过

this works, but wearable service onDataChanged never called

穿着服务

   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
                 }
   }
 }

我卡在这里,提前感谢您的帮助

I am stuck here, thank you for help in advance

推荐答案

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

Did you connect to the googleclientapi in your service?

mGoogleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).addConnectionCallbacks(this).建造();mGoogleApiClient.connect()

mGoogleApiClient = new GoogleApiClient.Builder(context) .addApi(Wearable.API) .addConnectionCallbacks(this) .build();mGoogleApiClient.connect()

另请查看此帖子:

WearableListenerService,onDataChanged() 未被调用

这篇关于onDataChanged 没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:56