gpt4 book ai didi

com.google.android.gms.wearable.Wearable类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 01:09:05 26 4
gpt4 key购买 nike

本文整理了Java中com.google.android.gms.wearable.Wearable类的一些代码示例,展示了Wearable类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wearable类的具体详情如下:
包路径:com.google.android.gms.wearable.Wearable
类名称:Wearable

Wearable介绍

暂无

代码示例

代码示例来源:origin: googlesamples/android-DataLayer

@Override
public void onPause() {
  super.onPause();
  mDataItemGeneratorFuture.cancel(true /* mayInterruptIfRunning */);
  Wearable.getDataClient(this).removeListener(this);
  Wearable.getMessageClient(this).removeListener(this);
  Wearable.getCapabilityClient(this).removeListener(this);
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onResume() {
  super.onResume();
  Wearable.getDataClient(this).addListener(this);
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onResume() {
  super.onResume();
  Wearable.getMessageClient(this).addListener(this);
}

代码示例来源:origin: JimSeker/wearable

public void run() {
    //first get all the nodes, ie connected wearable devices.
    Task<List<Node>> nodeListTask =
      Wearable.getNodeClient(getApplicationContext()).getConnectedNodes();
    try {
      // Block on a task and get the result synchronously (because this is on a background
      // thread).
      List<Node> nodes = Tasks.await(nodeListTask);
      //Now send the message to each device.
      for (Node node : nodes) {
        Task<Integer> sendMessageTask =
          Wearable.getMessageClient(MainActivity.this).sendMessage(node.getId(), path, message.getBytes());
        try {
          // Block on a task and get the result synchronously (because this is on a background
          // thread).
          Integer result = Tasks.await(sendMessageTask);
          Log.v(TAG, "SendThread: message send to " + node.getDisplayName());
        } catch (ExecutionException exception) {
          Log.e(TAG, "Task failed: " + exception);
        } catch (InterruptedException exception) {
          Log.e(TAG, "Interrupt occurred: " + exception);
        }
      }
    } catch (ExecutionException exception) {
      Log.e(TAG, "Task failed: " + exception);
    } catch (InterruptedException exception) {
      Log.e(TAG, "Interrupt occurred: " + exception);
    }
  }
}

代码示例来源:origin: Calsign/APDE

public static void initMessageBroadcaster(final Context context) {
  Wearable.getCapabilityClient(context).addListener(new CapabilityClient.OnCapabilityChangedListener() {
    @Override
    public void onCapabilityChanged(@NonNull CapabilityInfo capabilityInfo) {
      updateBestNode(context);
    }
  }, "apde_receive_logs");
  
  // Can't do this on the main thread
  (new Thread(new Runnable() {
    @Override
    public void run() {
      updateBestNode(context);
    }
  })).start();
}

代码示例来源:origin: googlesamples/android-DataLayer

@WorkerThread
private Collection<String> getNodes() {
  HashSet<String> results = new HashSet<>();
  Task<List<Node>> nodeListTask =
      Wearable.getNodeClient(getApplicationContext()).getConnectedNodes();
  try {
    // Block on a task and get the result synchronously (because this is on a background
    // thread).
    List<Node> nodes = Tasks.await(nodeListTask);
    for (Node node : nodes) {
      results.add(node.getId());
    }
  } catch (ExecutionException exception) {
    Log.e(TAG, "Task failed: " + exception);
  } catch (InterruptedException exception) {
    Log.e(TAG, "Interrupt occurred: " + exception);
  }
  return results;
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onPause() {
  super.onPause();
  Wearable.getDataClient(this).removeListener(this);
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onPause() {
  super.onPause();
  Wearable.getMessageClient(this).removeListener(this);
}

代码示例来源:origin: JimSeker/wearable

Wearable.getNodeClient(getApplicationContext()).getConnectedNodes();
try {
      Wearable.getMessageClient(MainActivity.this).sendMessage(node.getId(), path, message.getBytes());

代码示例来源:origin: Calsign/APDE

private static void updateBestNode(Context context) {
  bestNodeId = null;
  
  try {
    CapabilityInfo info = Tasks.await(Wearable.getCapabilityClient(context).getCapability("apde_receive_logs", CapabilityClient.FILTER_REACHABLE));
    for (Node node : info.getNodes()) {
      if (node.isNearby()) {
        bestNodeId = node.getId();
      }
    }
  } catch (Exception e) {
    // Don't call printStackTrace() because that would make an infinite loop
    Log.e("apde", e.toString());
  }
}

代码示例来源:origin: googlesamples/android-DataLayer

@Override
public void onResume() {
  super.onResume();
  mDataItemGeneratorFuture =
      mGeneratorExecutor.scheduleWithFixedDelay(
          new DataItemGenerator(), 1, 5, TimeUnit.SECONDS);
  mStartActivityBtn.setEnabled(true);
  mSendPhotoBtn.setEnabled(mCameraSupported);
  // Instantiates clients without member variables, as clients are inexpensive to create and
  // won't lose their listeners. (They are cached and shared between GoogleApi instances.)
  Wearable.getDataClient(this).addListener(this);
  Wearable.getMessageClient(this).addListener(this);
  Wearable.getCapabilityClient(this)
      .addListener(this, Uri.parse("wear://"), CapabilityClient.FILTER_REACHABLE);
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onResume() {
  super.onResume();
  Wearable.getDataClient(this).addListener(this);
}

代码示例来源:origin: Calsign/APDE

public void run() {
    try {
      JSONObject json = new JSONObject();
      json.put("severity", Character.toString(severity));
      json.put("message", message);
      json.put("exception", exception);
      byte[] data = json.toString().getBytes();
      
      if (bestNodeId != null) {
        Wearable.getMessageClient(context).sendMessage(bestNodeId, "/apde_receive_logs", data);
      }
    } catch (Exception e) {
      // Don't call printStackTrace() because that would make an infinite loop
      Log.e("apde", e.toString());
    }
  }
});

代码示例来源:origin: Calsign/APDE

@Override
  public void run() {
    boolean successful = false;
    
    try {
      CapabilityInfo info = Tasks.await(Wearable.getCapabilityClient(context).getCapability("apde_run_watch_sketches", CapabilityClient.FILTER_REACHABLE));
      
      for (Node node : info.getNodes()) {
        if (node.isNearby()) {
          successful = true;
          break;
        }
      }
    } catch (ExecutionException | InterruptedException e) {
      e.printStackTrace();
    }
    
    if (successful) {
      callback.success();
    } else {
      callback.failure();
    }
  }
})).start();

代码示例来源:origin: JimSeker/wearable

@Override
public void onPause() {
  super.onPause();
  Wearable.getDataClient(this).removeListener(this);
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onResume() {
  super.onResume();
  Wearable.getMessageClient(this).addListener(this);
}

代码示例来源:origin: Calsign/APDE

protected boolean makeFileFromAsset(Asset asset, File destFile) {
  try {
    InputStream inputStream = Tasks.await(Wearable.getDataClient(this).getFdForAsset(asset)).getInputStream();
    if (inputStream != null) {
      createFileFromInputStream(inputStream, destFile, true);
      return true;
    }
  } catch (ExecutionException | InterruptedException | IOException e) {
    e.printStackTrace();
  }
  
  return false;
}

代码示例来源:origin: JimSeker/wearable

@Override
public void onPause() {
  super.onPause();
  Wearable.getMessageClient(this).removeListener(this);
}

代码示例来源:origin: googlesamples/android-DataLayer

@Override
  public void run() {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(COUNT_PATH);
    putDataMapRequest.getDataMap().putInt(COUNT_KEY, count++);
    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    request.setUrgent();
    LOGD(TAG, "Generating DataItem: " + request);
    Task<DataItem> dataItemTask =
        Wearable.getDataClient(getApplicationContext()).putDataItem(request);
    try {
      // Block on a task and get the result synchronously (because this is on a background
      // thread).
      DataItem dataItem = Tasks.await(dataItemTask);
      LOGD(TAG, "DataItem saved: " + dataItem);
    } catch (ExecutionException exception) {
      Log.e(TAG, "Task failed: " + exception);
    } catch (InterruptedException exception) {
      Log.e(TAG, "Interrupt occurred: " + exception);
    }
  }
}

代码示例来源:origin: googlesamples/android-DataLayer

@WorkerThread
private void sendStartActivityMessage(String node) {
  Task<Integer> sendMessageTask =
      Wearable.getMessageClient(this).sendMessage(node, START_ACTIVITY_PATH, new byte[0]);
  try {
    // Block on a task and get the result synchronously (because this is on a background
    // thread).
    Integer result = Tasks.await(sendMessageTask);
    LOGD(TAG, "Message sent: " + result);
  } catch (ExecutionException exception) {
    Log.e(TAG, "Task failed: " + exception);
  } catch (InterruptedException exception) {
    Log.e(TAG, "Interrupt occurred: " + exception);
  }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com