当前位置: 首页>>代码示例>>Java>>正文


Java NodeApi类代码示例

本文整理汇总了Java中com.google.android.gms.wearable.NodeApi的典型用法代码示例。如果您正苦于以下问题:Java NodeApi类的具体用法?Java NodeApi怎么用?Java NodeApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NodeApi类属于com.google.android.gms.wearable包,在下文中一共展示了NodeApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleActionSendMessage

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Handle the message sending action in the provided background thread.
 */
private void handleActionSendMessage(String mode) {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
        mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
    }

    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

    // Send the Do Not Disturb mode message to all devices (nodes)
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();

        if (!result.getStatus().isSuccess()){
            Log.e(TAG, "Failed to send message to " + node.getDisplayName());
        } else {
            Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
        }
    }
}
 
开发者ID:blunden,项目名称:DoNotDisturbSync,代码行数:26,代码来源:WearMessageSenderService.java

示例2: handleActionSendMessage

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Handle the message sending action in the provided background thread.
 */
private void handleActionSendMessage(String mode) {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
        mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
    }

    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

    // Send the Do Not Disturb mode message to all devices (nodes)
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();

        if (!result.getStatus().isSuccess()){
            Log.e(TAG, "Failed to send message to " + node.getDisplayName());
        } else {
            Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
        }
    }

    //mGoogleApiClient.disconnect();
}
 
开发者ID:blunden,项目名称:DoNotDisturbSync,代码行数:28,代码来源:WearMessageSenderService.java

示例3: onConnected

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
            .setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
                @Override
                public void onResult(NodeApi.GetConnectedNodesResult nodes) {
                    for (Node node : nodes.getNodes()) {
                        if (node != null && node.isNearby()) {
                            mNode = node;
                            Log.d("packtchat", "Connected to " + mNode.getDisplayName());
                        }
                    }
                    if (mNode == null) {
                        Log.d("packtchat", "Not connected!");
                    }
                }
            });
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:19,代码来源:MainActivity.java

示例4: sendMessageToHandheld

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Sends the given message to the handheld.
 * @param path message path
 * @param message the message
 */
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String path, final @NonNull String message) {
	new Thread(new Runnable() {
		@Override
		public void run() {
			final GoogleApiClient client = new GoogleApiClient.Builder(context)
					.addApi(Wearable.API)
					.build();
			client.blockingConnect();

			final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
			for(Node node : nodes.getNodes()) {
				final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), path, message.getBytes()).await();
				if (!result.getStatus().isSuccess()){
					Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
				}
			}
			client.disconnect();
		}
	}).start();
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:26,代码来源:ActionReceiver.java

示例5: sendMessageToHandheld

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Sends the given command to the handheld.
 *
 * @param command the message
 */
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String command) {
	new Thread(new Runnable() {
		@Override
		public void run() {
			final GoogleApiClient client = new GoogleApiClient.Builder(context)
					.addApi(Wearable.API)
					.build();
			client.blockingConnect();

			final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
			for (Node node : nodes.getNodes()) {
				final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), Constants.UART.COMMAND, command.getBytes()).await();
				if (!result.getStatus().isSuccess()) {
					Log.w(TAG, "Failed to send " + Constants.UART.COMMAND + " to " + node.getDisplayName());
				}
			}
			client.disconnect();
		}
	}).start();
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:26,代码来源:UARTCommandsActivity.java

示例6: sendMessageToWearables

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Sends the given message to all connected wearables. If the path is equal to {@link Constants.UART#DEVICE_DISCONNECTED} the service will be stopped afterwards.
 * @param path message path
 * @param message the message
 */
private void sendMessageToWearables(final @NonNull String path, final @NonNull String message) {
	if(mGoogleApiClient.isConnected()) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
				for(Node node : nodes.getNodes()) {
					Logger.v(getLogSession(), "[WEAR] Sending message '" + path + "' to " + node.getDisplayName());
					final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, message.getBytes()).await();
					if(result.getStatus().isSuccess()){
						Logger.i(getLogSession(), "[WEAR] Message sent");
					} else {
						Logger.w(getLogSession(), "[WEAR] Sending message failed: " + result.getStatus().getStatusMessage());
						Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
					}
				}
				if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
					stopService();
			}
		}).start();
	} else {
		if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
			stopService();
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:31,代码来源:UARTService.java

示例7: findAllWearDevices

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
@SuppressLint("LongLogTag")
private void findAllWearDevices() {
    Log.d(TAG, "findAllWearDevices()");

    PendingResult<NodeApi.GetConnectedNodesResult> pendingResult =
            Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

    pendingResult.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
        @Override
        public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {

            if (getConnectedNodesResult.getStatus().isSuccess()) {
                mAllConnectedNodes = getConnectedNodesResult.getNodes();
                verifyNodeAndUpdateUI();
                Log.e("Connected Nodes", "->"+mAllConnectedNodes.toString());
                findWearDevicesWithApp();

            } else {
                Log.d(TAG, "Failed NodeApi: " + getConnectedNodesResult.getStatus());
            }
        }
    });
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:24,代码来源:DeviceWearConnectionFragment.java

示例8: sendMessageToDevice

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
private void sendMessageToDevice(final String key) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (mGoogleApiClient == null) {
                mGoogleApiClient = (new com.google.android.gms.common.api.GoogleApiClient.Builder(ConfigDataListenerService.this)).addConnectionCallbacks(ConfigDataListenerService.this).addOnConnectionFailedListener(ConfigDataListenerService.this).addApi(Wearable.API).build();
            }
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
            if (nodes != null && nodes.getNodes() != null) {
                for (Node node : nodes.getNodes()) {
                    MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), key, null).await();
                    if (!result.getStatus().isSuccess()) {
                        Log.e(TAG, "Error during sending message");
                    } else {
                        Log.i(TAG, "Success!! sent to: " + node.getDisplayName());
                    }
                }
            }
        }
    }).start();
}
 
开发者ID:mladenbabic,项目名称:Advanced_Android_Development_Wear,代码行数:22,代码来源:ConfigDataListenerService.java

示例9: fetchConfigDataMap

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
public static void fetchConfigDataMap(final GoogleApiClient client,
        final FetchConfigDataMapCallback callback, final String path) {

    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(path)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
开发者ID:mladenbabic,项目名称:Advanced_Android_Development_Wear,代码行数:20,代码来源:DigitalWatchFaceUtil.java

示例10: onMessageReceived

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Handle messages from the phone
 * @param messageEvent new message from the phone
 */
@Override
public void onMessageReceived(MessageEvent messageEvent) {

    if (messageEvent.getPath().equals("/start")) {
        dataManager.turnSensorOn(Integer.valueOf(new String(messageEvent.getData())));
    }

    else if (messageEvent.getPath().equals("/stop")){
        dataManager.turnSensorOff(Integer.valueOf(new String(messageEvent.getData())));
    }

    else if (messageEvent.getPath().equals("/stopAll")){
        dataManager.turnAllSensorsOff();
    }

    else if (messageEvent.getPath().equals("/ping")){
        NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(apiClient).await();
        for(Node node : nodes.getNodes()) {
            Wearable.MessageApi.sendMessage(apiClient, node.getId(), "/connected", null).await();
        }
    }
}
 
开发者ID:ibm-wearables-sdk-for-mobile,项目名称:ibm-wearables-android-sdk,代码行数:27,代码来源:MessageReceiverService.java

示例11: fetchConfigDataMap

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Asynchronously fetches the current config {@link DataMap} for {@link com.dimitrioskanellopoulos.athletica.WatchFaceService}
 * and passes it to the given callback.
 * <p/>
 * If the current config {@link DataItem} doesn't exist, it isn't created and the callback
 * receives an empty DataMap.
 */
public static void fetchConfigDataMap(final GoogleApiClient client,
                                      final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(@NonNull NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(ConfigurationHelper.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
开发者ID:jimmykane,项目名称:Athletica,代码行数:26,代码来源:ConfigurationHelper.java

示例12: onConnected

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle)
{
    Log.v("app", "onConnected");

    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>()
    {
        @Override
        public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult)
        {
            int nodesSize = getConnectedNodesResult.getNodes().size();

            Log.v("app", "getConnectedNodes: " + nodesSize);

            if (nodesSize > 0)
            {
                mNode = getConnectedNodesResult.getNodes().get(0);
                sendConnected();

                //createChannel();
            }
        }
    });
}
 
开发者ID:spiretos,项目名称:WeaRemote,代码行数:25,代码来源:Communicator.java

示例13: sendStepCountMessage

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Send the current step count to the phone. This does not require guarantee of message delivery. As, if
 * the message is not delivered, the count will get updated when second message gets delivered.
 * So, we are using messages api for passing the data that are usful at the current moment only.
 * <p>
 * <B>Note: </B> Messages will block the UI thread while sending. So, we should send messages in background
 * thread only.
 *
 * @param stepCount current step count.
 */
private void sendStepCountMessage(final String stepCount) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
            for (Node node : nodes.getNodes()) {
                MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
                        mGoogleApiClient, node.getId(), STEP_COUNT_MESSAGES_PATH, stepCount.getBytes()).await();

                //check  if the message is delivered?
                Log.d("Messages Api", result.getStatus().isSuccess() ? "Sent successfully" : "Sent failed.");
            }
        }
    }).start();
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:26,代码来源:TrackActivity.java

示例14: fetchConfigDataMap

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
/**
 * Asynchronously fetches the current config {@link DataMap} for {@link SonicBoomFace}
 * and passes it to the given callback.
 * <p>
 * If the current config {@link DataItem} doesn't exist, it isn't created and the callback
 * receives an empty DataMap.
 */
public static void fetchConfigDataMap(final GoogleApiClient client,
                                      final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(WatchFaceUtil.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:26,代码来源:WatchFaceUtil.java

示例15: fetchConfigDataMap

import com.google.android.gms.wearable.NodeApi; //导入依赖的package包/类
public static void fetchConfigDataMap(final GoogleApiClient client,
                                      final FetchConfigDataMapCallback callback) {
    Wearable.NodeApi.getLocalNode(client).setResultCallback(
            new ResultCallback<NodeApi.GetLocalNodeResult>() {
                @Override
                public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
                    String localNode = getLocalNodeResult.getNode().getId();
                    Uri uri = new Uri.Builder()
                            .scheme("wear")
                            .path(WatchFaceUtil.PATH_WITH_FEATURE)
                            .authority(localNode)
                            .build();
                    Wearable.DataApi.getDataItem(client, uri)
                            .setResultCallback(new DataItemResultCallback(callback));
                }
            }
    );
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:19,代码来源:WatchFaceUtil.java


注:本文中的com.google.android.gms.wearable.NodeApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。