After some digging, I found a solution. Hope this helps someone else.
We can send a message from Activity to WearableListenerService using Wearable.MessageApi functions. If Activity and WearableListenerService are on the same Node (device), we need to get an instance of the local node (the current Node from which the message was sent) to send the message below
NodeApi.GetLocalNodeResult nodes = Wearable.NodeApi.getLocalNode(mGoogleApiClient).await();
but not
NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
which is used to get a list of other devices (for example, wear) connected to the phone.
So, I was able to successfully send a message from my Activity to WearableListenerService as follows
Action code
public class PhoneActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private static final String TAG = "PhoneActivity"; public static final String CONFIG_START = "config/start"; public static final String CONFIG_STOP= "config/stop" Intent intent; TextView txtview; GoogleApiClient mGoogleApiClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_phone); if(null == mGoogleApiClient) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); Log.v(TAG, "GoogleApiClient created"); } if(!mGoogleApiClient.isConnected()){ mGoogleApiClient.connect(); Log.v(TAG, "Connecting to GoogleApiClient.."); } startService(new Intent(this, PhoneService.class)); } @Override public void onConnectionSuspended(int cause) { Log.v(TAG,"onConnectionSuspended called"); } @Override public void onConnectionFailed(ConnectionResult connectionResult) { Log.v(TAG,"onConnectionFailed called"); } @Override public void onConnected(Bundle connectionHint) { Log.v(TAG,"onConnected called"); } @Override protected void onStart() { super.onStart(); Log.v(TAG, "onStart called"); } @Override public boolean onCreateOptionsMenu(Menu menu) {
Service Code
public class PhoneService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{ private static final String TAG = "PhoneService"; public static final String CONFIG_START = "config/start"; public static final String CONFIG_STOP = "config/stop"; GoogleApiClient mGoogleApiClient; public PhoneService() { } @Override public void onCreate() { super.onCreate(); Log.v(TAG, "Created"); if(null == mGoogleApiClient) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); Log.v(TAG, "GoogleApiClient created"); } if(!mGoogleApiClient.isConnected()){ mGoogleApiClient.connect(); Log.v(TAG, "Connecting to GoogleApiClient.."); } } @Override public void onDestroy() { Log.v(TAG, "Destroyed"); if(null != mGoogleApiClient){ if(mGoogleApiClient.isConnected()){ mGoogleApiClient.disconnect(); Log.v(TAG, "GoogleApiClient disconnected"); } } super.onDestroy(); } @Override public void onConnectionSuspended(int cause) { Log.v(TAG,"onConnectionSuspended called"); } @Override public void onConnectionFailed(ConnectionResult connectionResult) { Log.v(TAG,"onConnectionFailed called"); } @Override public void onConnected(Bundle connectionHint) { Log.v(TAG,"onConnected called"); } @Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); Log.v(TAG, "Data Changed"); } @Override public void onMessageReceived(MessageEvent messageEvent) { super.onMessageReceived(messageEvent); if(messageEvent.getPath().equals(CONFIG_START)){
Blackcursor
source share