Back to project page dNote.
The source code is released under:
GNU General Public License
If you think the Android project dNote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.digutsoft.note; //from w w w .j ava 2 s .com import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.wearable.activity.ConfirmationActivity; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.wearable.MessageApi; import com.google.android.gms.wearable.Node; import com.google.android.gms.wearable.NodeApi; import com.google.android.gms.wearable.Wearable; public class DMWearVoiceAction extends Activity { private static final String dNoteSaveNote = "/dNote-Save-Note"; private GoogleApiClient googleApiClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) { Intent intent = new Intent(DMWearVoiceAction.this, ConfirmationActivity.class); intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.FAILURE_ANIMATION); startActivity(intent); } }) .build(); googleApiClient.connect(); sendMessage(dNoteSaveNote, getIntent().getStringExtra(Intent.EXTRA_TEXT)); } private void sendMessage(final String path, final String message) { new Thread(new Runnable() { @Override public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(); for (Node node : nodes.getNodes()) { MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, message.getBytes()).await(); if(result.getStatus().isSuccess()) { Intent intent = new Intent(DMWearVoiceAction.this, ConfirmationActivity.class); intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.SUCCESS_ANIMATION); startActivity(intent); finish(); } else { Intent intent = new Intent(DMWearVoiceAction.this, ConfirmationActivity.class); intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.FAILURE_ANIMATION); startActivity(intent); } } } }).start(); } protected void onDestroy() { super.onDestroy(); googleApiClient.disconnect(); } }