當前位置: 首頁>>代碼示例>>Java>>正文


Java Node類代碼示例

本文整理匯總了Java中com.google.android.gms.wearable.Node的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Node類屬於com.google.android.gms.wearable包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleActionSendMessage

import com.google.android.gms.wearable.Node; //導入依賴的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.Node; //導入依賴的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.Node; //導入依賴的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.Node; //導入依賴的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.Node; //導入依賴的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.Node; //導入依賴的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: sendMessageToDevice

import com.google.android.gms.wearable.Node; //導入依賴的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

示例8: onMessageReceived

import com.google.android.gms.wearable.Node; //導入依賴的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

示例9: sendStepCountMessage

import com.google.android.gms.wearable.Node; //導入依賴的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

示例10: openChannel

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
/**
 * Initiates opening a channel to a nearby node. When done, it will call the {@code listener}
 * and passes the status code of the request and the channel that was opened. Note that if the
 * request was not successful, the channel passed to the listener will be {@code null}. <br/>
 * <strong>Note:</strong> It is the responsibility of the caller to close the channel and the
 * stream when it is done.
 *
 * @param node     The node to which a channel should be opened. Note that {@code
 *                 node.isNearby()} should return {@code true}
 * @param path     The path used for opening a channel
 * @param listener The listener that is called when this request is completed.
 */
public void openChannel(Node node, String path,
        final FileTransfer.OnChannelReadyListener listener) {
    if (node.isNearby()) {
        Wearable.ChannelApi.openChannel(
                mGoogleApiClient, node.getId(), path).setResultCallback(
                new ResultCallback<ChannelApi.OpenChannelResult>() {
                    @Override
                    public void onResult(ChannelApi.OpenChannelResult openChannelResult) {
                        int statusCode = openChannelResult.getStatus().getStatusCode();
                        Channel channel = null;
                        if (openChannelResult.getStatus().isSuccess()) {
                            channel = openChannelResult.getChannel();
                        } else {
                            Log.e(TAG, "openChannel(): Failed to get channel, status code: "
                                    + statusCode);
                        }
                        listener.onChannelReady(statusCode, channel);
                    }
                });
    } else {
        Log.e(TAG, "openChannel(): Node should be nearby, you have: " + node);
    }
}
 
開發者ID:csarron,項目名稱:GmsWear,代碼行數:36,代碼來源:GmsWear.java

示例11: runBenchmarkTest

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
private boolean runBenchmarkTest(Node node, String pathdesc, String path, byte[] payload, boolean bDuplicateTest) {
    if (mAsyncBenchmarkTester != null) {
        Log.d(TAG, "Benchmark: runAsyncBenchmarkTester mAsyncBenchmarkTester != null lastRequest:" + JoH.dateTimeText(lastRequest));
        if (mAsyncBenchmarkTester.getStatus() != AsyncTask.Status.FINISHED) {
            Log.d(TAG, "Benchmark: mAsyncBenchmarkTester let process complete, do not start new process.");
            //mAsyncBenchmarkTester.cancel(true);
        }
        //mAsyncBenchmarkTester = null;
    } else {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            Log.d(TAG, "Benchmark: runAsyncBenchmarkTester SDK < M call execute lastRequest:" + JoH.dateTimeText(lastRequest));
            mAsyncBenchmarkTester = (AsyncBenchmarkTester) new AsyncBenchmarkTester(Home.getAppContext(), node, pathdesc, path, payload, bDuplicateTest).execute();
        } else {
            Log.d(TAG, "Benchmark: runAsyncBenchmarkTester SDK >= M call executeOnExecutor lastRequest:" + JoH.dateTimeText(lastRequest));
            mAsyncBenchmarkTester = (AsyncBenchmarkTester) new AsyncBenchmarkTester(Home.getAppContext(), node, pathdesc, path, payload, bDuplicateTest).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
    return false;
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:20,代碼來源:ListenerService.java

示例12: sendMessage

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
private void sendMessage(final String path, final String message) {
    new Thread( new Runnable() {
        @Override
        public void run() {
            NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes( mApiClient ).await();
            for(Node node : nodes.getNodes()) {
                MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(
                        mApiClient, node.getId(), path, message.getBytes() ).await();
            }

            runOnUiThread( new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), "m to phon" + message, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }).start();
}
 
開發者ID:mariopce,項目名稱:android-wear-bilateral-communication,代碼行數:20,代碼來源:WearActivity.java

示例13: setLocalNodeName

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
private void setLocalNodeName () {
    forceGoogleApiConnect();
    PendingResult<NodeApi.GetLocalNodeResult> result = Wearable.NodeApi.getLocalNode(googleApiClient);
    result.setResultCallback(new ResultCallback<NodeApi.GetLocalNodeResult>() {
        @Override
        public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
            if (!getLocalNodeResult.getStatus().isSuccess()) {
                Log.e(TAG, "ERROR: failed to getLocalNode Status=" + getLocalNodeResult.getStatus().getStatusMessage());
            } else {
                Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage());
                Node getnode = getLocalNodeResult.getNode();
                localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
                Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
            }
        }
    });
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:18,代碼來源:ListenerService.java

示例14: onCapabilityChanged

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
    Node phoneNode = updatePhoneSyncBgsCapability(capabilityInfo);
    Log.d(TAG, "onCapabilityChanged mPhoneNodeID:" + (phoneNode != null ? phoneNode.getId() : ""));//mPhoneNodeId
    //onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER

    if (phoneNode != null && phoneNode.getId().length() > 0) {
        if (JoH.ratelimit("on-connected-nodes-sync", 1200)) {
            Log.d(TAG, "onCapabilityChanged event - attempting resync");
            requestData();
        } else {
            Log.d(TAG, "onCapabilityChanged event - ratelimited");
        }
        sendPrefSettings();//from onPeerConnected
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:17,代碼來源:ListenerService.java

示例15: onPeerConnected

import com.google.android.gms.wearable.Node; //導入依賴的package包/類
@Override
public void onPeerConnected(com.google.android.gms.wearable.Node peer) {//KS onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER

    super.onPeerConnected(peer);
    String id = peer.getId();
    String name = peer.getDisplayName();
    Log.d(TAG, "onPeerConnected peer name & ID: " + name + "|" + id);
    sendPrefSettings();
    if (mPrefs.getBoolean("enable_wearG5", false)) {//watch_integration
        Log.d(TAG, "onPeerConnected call initWearData for node=" + peer.getDisplayName());
        initWearData();
        //Only stop service if Phone will rely on Wear Collection Service
        if (mPrefs.getBoolean("force_wearG5", false)) {
            Log.d(TAG, "onPeerConnected force_wearG5=true Phone stopBtService and continue to use Wear G5 BT Collector");
            stopBtService();
        } else {
            Log.d(TAG, "onPeerConnected onPeerConnected force_wearG5=false Phone startBtService");
            startBtService();
        }
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:22,代碼來源:WatchUpdaterService.java


注:本文中的com.google.android.gms.wearable.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。