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


Java NodeApi.GetConnectedNodesResult方法代码示例

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


在下文中一共展示了NodeApi.GetConnectedNodesResult方法的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: 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

示例4: 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

示例5: doInBackground

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
@Override
protected Void doInBackground(DataMap... params) {
    try {
        final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
        for (Node node : nodes.getNodes()) {
            for (DataMap dataMap : params) {
                PutDataMapRequest putDMR = PutDataMapRequest.create(path);
                putDMR.getDataMap().putAll(dataMap);
                PutDataRequest request = putDMR.asPutDataRequest();
                DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
                if (result.getStatus().isSuccess()) {
                    Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
                } else {
                    Log.d(TAG, "ERROR: failed to send DataMap");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception sending data to wear: " + e.toString());
    }
    return null;
}
 
开发者ID:MilosKozak,项目名称:AndroidAPS,代码行数:23,代码来源:SendToDataLayerThread.java

示例6: run

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
public void run() {
    if ((objectArray.length / 1024) > 100) {
        throw new RuntimeException("Object is too big to push it via Google Play Services");
    }
    GoogleApiClient googleApiClient = SendWearManager.getInstance(context);
    googleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
    if(nodes != null) {
        for (Node node : nodes.getNodes()) {
            MessageApi.SendMessageResult result;
            result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, objectArray).await();
            if (!result.getStatus().isSuccess()) {
                Log.v(TAG, "ERROR: failed to send Message via Google Play Services");
            }
            Log.d(TAG, "run send:");
        }
    }
}
 
开发者ID:tajchert,项目名称:SpritzerWear,代码行数:19,代码来源:SendMessageToNode.java

示例7: run

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
@Override
public void run() {
    if ((mObjectArray.length / 1024) > 100) {
        throw new RuntimeException("Object is too big to push it via Google Play Services");
    }
    if (mGoogleApiClient != null) {
        NodeApi.GetConnectedNodesResult nodes =
                Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
        for (Node node : nodes.getNodes()) {
            MessageApi.SendMessageResult result;
            result = Wearable.MessageApi.sendMessage(
                    mGoogleApiClient, node.getId(), mPath, mObjectArray).await();
            if (!result.getStatus().isSuccess()) {
                Log.v(TAG, "ERROR: failed to send Message via Google Play Services");
            } else {
                Log.d(TAG, "run: Sent message to " + mPath);
            }
        }
    } else {
        Log.e(TAG, "run: GoogleApiClient was null");
    }
}
 
开发者ID:jordond,项目名称:powerhour,代码行数:23,代码来源:WearData.java

示例8: run

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
@Override
public void run() {
	final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApi(Wearable.API).build();
	mGoogleApiClient.connect();
	final PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

	nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
		@Override
		public void onResult(NodeApi.GetConnectedNodesResult result) {
			if (result.getNodes().isEmpty()) {
				wearConnected = false;
			} else {
				for (Node node : result.getNodes()) {
					mConnectedNodes.add(node.getId());
					wearConnected = true;
				}
			}
		}
	});
}
 
开发者ID:ngageoint,项目名称:mage-chronostouch-android,代码行数:21,代码来源:DataManager.java

示例9: doInBackground

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    if (googleApiClient.isConnected()) {
        if (System.currentTimeMillis() - lastRequest > 20 * 1000) { // enforce 20-second debounce period
            lastRequest = System.currentTimeMillis();

            NodeApi.GetConnectedNodesResult nodes =
                    Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            for (Node node : nodes.getNodes()) {
                Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), WEARABLE_RESEND_PATH, null);
            }
        }
    } else
        googleApiClient.connect();
    return null;
}
 
开发者ID:StephenBlackWasAlreadyTaken,项目名称:NightWatch,代码行数:17,代码来源:ListenerService.java

示例10: sendMessage

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
public void sendMessage(final String path, final String message) {
	Runnable sendData = new Runnable() {
		@Override
		public void run() {

			final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApi(Wearable.API).build();
			mGoogleApiClient.connect();
			final PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

			nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
				@Override
				public void onResult(NodeApi.GetConnectedNodesResult result) {
					for (Node node : result.getNodes()) {
						Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, message.getBytes());
					}
				}
			});


		}
	};
	Handler handler = new Handler();
	handler.post(sendData);
}
 
开发者ID:ngageoint,项目名称:mage-chronostouch-android,代码行数:25,代码来源:DataManager.java

示例11: onResult

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
@Override
public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
    nodesList = new ArrayList<>();
    for (Node node : getConnectedNodesResult.getNodes()) {
        nodesList.add(node);
        if(nodesListener != null) {
            nodesListener.onNewConnectedNode(node);
        }
    }
    if(nodesList.size() > 0){
        connectionState = NodeConnectionState.Connected;
    }
    if(nodesListener != null) {
        nodesListener.nodesChanged(nodesList);
    }
}
 
开发者ID:tajchert,项目名称:DetectWear,代码行数:17,代码来源:DetectWear.java

示例12: sendHeadlineToReadList

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
/**
 * Send the particular Url string to be opened on the phone
 */
public void sendHeadlineToReadList(final FeedHeadline headline) {
    //TODO: Come back and refactor this to be more general and could be used elsewhere
    AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            ConnectionResult connectionResult = mApiClient.blockingConnect(30, TimeUnit.SECONDS);
            if (connectionResult.isSuccess()) {
                NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mApiClient).await();

                if (nodes.getNodes().size() > 0) {
                    Node connectedNode = nodes.getNodes().get(0);

                    String headlineJSON = new Gson().toJson(headline);
                    Wearable.MessageApi.sendMessage(mApiClient, connectedNode.getId(), "/saveFeed", headlineJSON.getBytes());
                }
            }

            return null;
        }
    };

    task.execute();
}
 
开发者ID:creativedrewy,项目名称:WeaRSS,代码行数:27,代码来源:DataToPhoneService.java

示例13: run

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
public void run() {
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleClient).await();
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleClient, node.getId(), path, message.getBytes()).await();
        if (result.getStatus().isSuccess()) {
            Log.v("myTag", "Message: {" + message + "} sent to: " + node.getDisplayName());
        } else {
            // Log an error
            Log.v("myTag", "ERROR: failed to send Message");
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:13,代码来源:MainActivity.java

示例14: getMWearable

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
private void getMWearable()
{
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes( mApiClient ).await();
    List<Node> list=nodes.getNodes();

    if(list.size()>0)
        mWearableID=list.get(0).getId();
}
 
开发者ID:juanpomares,项目名称:Unity-Wear-Controller,代码行数:9,代码来源:MainActivity.java

示例15: getBestNodeId

import com.google.android.gms.wearable.NodeApi; //导入方法依赖的package包/类
private String getBestNodeId(){
    String bestNodeId = null;
    // Find a nearby node or pick one arbitrarily
    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
    for (Node node : nodes.getNodes()) {
        if (node.isNearby()) {
            return node.getId();
        }
        bestNodeId = node.getId();
    }
    return bestNodeId;
}
 
开发者ID:MVK16,项目名称:stayawhile-android,代码行数:13,代码来源:WearMessageHandler.java


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