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


Java WearableStatusCodes类代码示例

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


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

示例1: fireMessage

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
protected void fireMessage(final String command) {
    if (phoneNodeId == null) {
        //bad, we cannot send message
    } else {
        //fire the message to the first connected node in list
        Log.d(TAG, "Sending message to Node with ID: " + phoneNodeId);

        PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(mGoogleApiClient, phoneNodeId, command, null);
        messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
            @Override
            public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                Status status = sendMessageResult.getStatus();
                Log.d(TAG, "Status: " + status.toString());
                if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
                    Log.e(TAG,"Something go wrong during sending command... "+command);
                } else {
                    Log.d(TAG,"Message sent successfully to node. "+command);
                }
            }
        });
    }
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:23,代码来源:SonicBoomFace.java

示例2: sendSelectedImage

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
public static void sendSelectedImage(final Uri uri, ImageView imageView) {
    final Context context = imageView.getContext();

    // show image locally
    Glide.with(context).load(uri).into(imageView);

    // send to wearable
    FileTransfer fileTransferHighLevel = new FileTransfer.Builder()
            .setOnChannelOutputStreamListener(new FileTransfer.OnChannelOutputStreamListener() {
                @Override
                public void onOutputStreamForChannelReady(int statusCode, Channel channel,
                        final OutputStream outputStream) {
                    if (statusCode != WearableStatusCodes.SUCCESS) {
                        Logger.e("Failed to open a channel, status code: " + statusCode);
                        return;
                    }
                    sendFile(context, uri, outputStream);
                }
            }).build();
    fileTransferHighLevel.requestOutputStream();

}
 
开发者ID:csarron,项目名称:GmsWear,代码行数:23,代码来源:Utils.java

示例3: doInBackground

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
@Override
protected com.google.android.gms.common.api.Status doInBackground(SoundProfile... params) {

    final List<Node> connectedNodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await().getNodes();

    if (connectedNodes.isEmpty()) {
        return new com.google.android.gms.common.api.Status(WearableStatusCodes.ERROR);
    }

    com.google.android.gms.common.api.Status status = null;

    for (Node node : connectedNodes) {
        if (status == null || !status.isSuccess()) {
            status = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), params[0].name(), null).await().getStatus();
        }
    }

    return status;
}
 
开发者ID:tobiasheine,项目名称:WearControl,代码行数:20,代码来源:SoundProfileChangeTask.java

示例4: startTransfer

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
/**
 * Initiates the transfer of a file to the target node. Using this method, a file can be
 * transferred without any additional work on the receiver end although the receiver can
 * register a {@link DataConsumer#onFileReceivedResult(int, String, File, String)}
 * to be notified when the transfer is completed or when it fails.
 * Using {@link DataConsumer#onSendFileResult(int, String)}, the sender node can also
 * learn about the status of the file transfer request.
 */
public void startTransfer() {
    assertFileTransferParams();
    final Uri uri = Uri.fromFile(mFile);
    String path = buildPath(mTargetName, mRequestId, mFile.length());
    final GmsWear gmsWear = getInstance();
    if (mNode == null) {
        return;
    }

    gmsWear.openChannel(mNode, path, new OnChannelReadyListener() {
        @Override
        public void onChannelReady(int statusCode, Channel channel) {
            if (statusCode != WearableStatusCodes.SUCCESS) {
                Log.e(TAG, "transfer(): Failed to open channel; status code= " + statusCode);
                if (mFileTransferResultListener != null) {
                    mFileTransferResultListener.onFileTransferStatusResult(statusCode);
                }
                return;
            }

            gmsWear.sendFile(mRequestId, channel, uri, 0, -1, new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
                        Log.e(TAG, "transfer(): Failed to send file; status code= " + status
                                .getStatusCode());
                    }
                    if (mFileTransferResultListener != null) {
                        mFileTransferResultListener
                                .onFileTransferStatusResult(status.getStatusCode());
                    }
                }
            });
        }
    });
}
 
开发者ID:csarron,项目名称:GmsWear,代码行数:45,代码来源:FileTransfer.java

示例5: fireMessage

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
private void fireMessage(final byte[] data, final String path,final int retryCount) {

        PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient);
        nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
            @Override
            public void onResult(NodeApi.GetConnectedNodesResult result) {
                for (int i = 0; i < result.getNodes().size(); i++) {
                    Node node = result.getNodes().get(i);
                    Log.v(TAG, "Phone firing message with path : " + path);

                    PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
                            path, data);
                    messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                        @Override
                        public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                            Status status = sendMessageResult.getStatus();
                            Timber.d("Status: " + status.toString());
                            if (status.getStatusCode() != WearableStatusCodes.SUCCESS) {
                                if(!status.isSuccess()) {
                                    if (retryCount > 5) return;
                                    soundThreadHandler.postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            fireMessage(data, path, retryCount + 1);
                                        }
                                    }, 1000 * retryCount);
                                }
                            }
                            if (path.equals(CommonIdentifiers.P2W_CHANGE_SETTINGS)) {
                                Intent messageIntent = new Intent();
                                messageIntent.setAction(Intent.ACTION_SEND);
                                messageIntent.putExtra("status", status.getStatusCode());
                                LocalBroadcastManager.getInstance(WearMessageListenerService.this).sendBroadcast(messageIntent);
                            }
                        }
                    });
                }
            }
        });
    }
 
开发者ID:wlky,项目名称:AnkiDroid-Wear,代码行数:41,代码来源:WearMessageListenerService.java

示例6: onCreate

import com.google.android.gms.wearable.WearableStatusCodes; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wear_activity);

    mGmsWear = GmsWear.getInstance();

    mMsgTextView = (TextView) findViewById(R.id.tv_msg);
    mMsgTextView.setKeepScreenOn(true);

    mImageView = (ImageView) findViewById(R.id.imageView);

    mMsgOneButton = (Button) findViewById(R.id.btn_msg_one);
    mMsgTwoButton = (Button) findViewById(R.id.btn_msg_two);
    mSyncButton = (Button) findViewById(R.id.btn_sync);

    mDataConsumer = new AbstractDataConsumer() {
        @Override
        public void onMessageReceived(MessageEvent messageEvent) {
            String msg = new String(messageEvent.getData());
            if (messageEvent.getPath().equals(PATH_MSG_ONE)) {
                setTextAsync(mMsgTextView, msg + PATH_MSG_ONE);
            } else if (messageEvent.getPath().equals(PATH_MSG_TWO)) {
                setTextAsync(mMsgTextView, msg + PATH_MSG_TWO);
            }
        }

        @Override
        public void onDataChanged(DataEvent event) {
            DataItem item = event.getDataItem();
            final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();

            if (event.getType() == DataEvent.TYPE_CHANGED) {
                String syncString = dataMap.getString(SYNC_KEY);
                setTextAsync(mMsgTextView, syncString);
            } else if (event.getType() == DataEvent.TYPE_DELETED) {
                Logger.d("DataItem Deleted" + event.getDataItem().toString());
            }

        }

        @Override
        public void onFileReceivedResult(int statusCode, String requestId, File savedFile,
                String originalName) {
            Logger.d(
                    "File Received: status=%d, requestId=%s, savedLocation=%s, originalName=%s",
                    statusCode, requestId, savedFile.getAbsolutePath(), originalName);

            Glide.with(getApplicationContext()).load(savedFile).into(mImageView);
        }

        @Override
        public void onInputStreamForChannelOpened(int statusCode, String requestId,
                final Channel channel, final InputStream inputStream) {
            if (statusCode != WearableStatusCodes.SUCCESS) {
                Logger.e("onInputStreamForChannelOpened(): " + "Failed to get input stream");
                return;
            }
            Logger.d("Channel opened for path: " + channel.getPath());
            setImageFromInputStream(inputStream, mImageView);

        }
    };

    checkPermissions();
}
 
开发者ID:csarron,项目名称:GmsWear,代码行数:67,代码来源:WearActivity.java


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