gpt4 book ai didi

Android Wearable.API 已弃用。我应该用什么代替?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:42 27 4
gpt4 key购买 nike

我正在使用以下内容:

GoogleApiClient mApiClient = new GoogleApiClient.Builder(this)
.addApi( Wearable.API )
...

因为 Wearable.API 被弃用了?什么是合适的替代品?

最佳答案

我发现了一些有用的好东西

private class StartWearableActivityTask extends AsyncTask<Void, Void, Void> {

final String key;

public StartWearableActivityTask(String msg){
key = msg;
}


@Override
protected Void doInBackground(Void... args) {
Collection<String> nodes = getNodes();
for (String node : nodes) {
sendStartActivityMessage(node,key);
}
return null;
}
}

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

@WorkerThread
private void sendStartActivityMessage(String node,String event) {

Task<Integer> sendMessageTask =
Wearable.getMessageClient(this).sendMessage(node, event, 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);


} catch (ExecutionException exception) {
Log.e(TAG, "Task failed: " + exception);

} catch (InterruptedException exception) {
Log.e(TAG, "Interrupt occurred: " + exception);
}
}

关于Android Wearable.API 已弃用。我应该用什么代替?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48099852/

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