16. 環境設定
Google API Clientの利用してBluetooth通信を可能に
Google API Clientインスタンス
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addConnectionCallbacks(this)
.addApi(Wearable.API)
.build();
mGoogleApiClient.connect();
18. Wear App
I. Intentを投げる
private static final int SPEECH_REQUEST_CODE = 0;
// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Start the activity, the intent will be
// populated with the speech text
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
19. Wear App
II. コールバックで処理データを加工
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE
&& resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
// Do something with spokenText
sendMessage("つぶやき", spokenText);
}
super.onActivityResult(requestCode, resultCode, data);
}
20. Wear App
Ⅲ. スマホデバイス側にデータ送信
1. Deviceを探索
2. 探索結果のコールバックをセット
// Instance for looking for smart phone device.
PendingResult<NodeApi.GetConnectedNodesResult> nodes =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);
// Sets callback for device.
nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(NodeApi.GetConnectedNodesResult result) {
// write what you want to do for your host app.
}
});