0

I am currently developing a simple application which required to send data from sony smartwatch 2 to a host application. I had read through the sample code and API reference which released by SONY but I cant understand how the control utility can be used.

I am try to push data to the host application and I am able to create application that sending data between two android phone through bluetooth but I am not able to transit it into sony smartwatch compatible code. Are there any hints or sample code which show me how the data/file/message can be sent from smartwatch to host application?

Biboo Chung
  • 121
  • 1
  • 2
  • 13
  • What data do you want to send? – weston Apr 13 '14 at 07:57
  • I want to send a string. In addition, I would like to send the string periodically. – Biboo Chung Apr 13 '14 at 11:40
  • What is your meaning? I am trying to trigger a control event and create and send a string. – Biboo Chung Apr 14 '14 at 00:16
  • What kind of control event? It's all a bit vague for me to answer. – weston Apr 14 '14 at 08:25
  • For example, when the user click a list item or a button, then the smartwatch send a string such as "hello" to the host application and the host application shows the string "hello" on the screen – Biboo Chung Apr 14 '14 at 08:37
  • You do know that your watch app is running on the phone? So there's no need to attempt to send data by Bluetooth. – weston Apr 14 '14 at 13:04
  • I am sorry that I am a beginner in android and smartwatch development so could you explain more? I have read through the documentation but I can't understand how to EXTEND an android application. – Biboo Chung Apr 14 '14 at 16:55

2 Answers2

0

Take a look at the project SampleControlExtension in the Sony Add-on SDK in the /samples folder. That should show you how to draw a layout on the screen and be a good starting point to learn how to draw and display text on the device.

mldeveloper
  • 2,253
  • 1
  • 13
  • 14
  • I have studied that sample code and I know how to trigger the event on the smartwatch but I can't understand how to control the host application on the phone from the smartwatch – Biboo Chung Apr 14 '14 at 17:00
  • I just saw that the SampleControlExtension demonstrated how can we trigger the input but I can't see the reaction of SampleControlExtension, are there any things that I missed? I saw that the documentation stated that this sample shows how the accessory supports output events but in fact, I can only see the reaction on clicking the menu button. – Biboo Chung Apr 14 '14 at 17:17
0

If you want to update an Activity from Control Extension, the easiest way is to use Intent. Here is an example of method, you can call from your extension after some event was evoked:

private void sendEventToActivity(String anyData) {
    Intent intent = new Intent(mContext, YourActivity.class);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    intent.putExtra("anyData", anyData);

    mContext.startActivity(intent);
}

And then override onNewIntent for your Activity:

@Override
protected void onNewIntent(Intent intent) {
    String anyData = intent.getStringExtra("anyData");
}

This way it communicates with running activity or create a new one, if not running yet.

peter.bartos
  • 11,855
  • 3
  • 51
  • 62