0

I am new to Sony Smartwatch development. I am facing some issues while creating a demo Sony Smart watch app. I have an EditText and a Button in my activity . When I click on the Button , the string in the EditText should be sent to the smart watch and displayed on a control . I should also be able to change the text on the watch from my apps activity.

UPDATE:

1) I want to start a smart watch control extension from my Main App activity and display a simple text on it 2) The text should be sent from the Main App Activity.

From what I have understood from the SDK example (Please correct me if am wrong) : 1) To take full control of the smart watch screen and to display a textview or an image , I need to extend ControlExtension class (In my case -> DemoControlSmartWatch.java). 2) I need to register a BroadcastReceiver (DemoReceiver.java) in the manifest , which will start the extension service (DemoExtensionService.java) when it receives an Intent from the Host Application And/Or from the Smart Connect App. 3) Also Created a class (DemoRegistrationInformation.java) which extends the RegistrationInformation class and takes care of the registration stuff. 4) I have an activity (MainActivity.java) with a Button .Now, I want to send a String to the ControlExtension on click of the button.

I have found that to start an extension I need to do the following

Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.example.sonytest");
intent.setPackage("com.sonyericsson.extras.liveware.emulator");
sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);

I tried writing this in the onCreate method of my MainActivity class, but it doesn't start my Control extension on the smart watch .Should I write the above code in the DemoExtensionService and bind my activity to the service ?

Nirav Sanghvi
  • 408
  • 3
  • 14
  • 2
    Same comments as above, I'm not sure what your question is. Also, have you reviewed the sample extensions in the Sony Add-on SDK? The sample Control extension should give you examples of what you are trying to do above. – mldeveloper Sep 23 '13 at 19:35

2 Answers2

2

Your demo seems to be inappropriate, I suggest you think of an app that will have also some practical use. If I understand your question correctly, the solution would be:

1) from your Activity you need to start your Extension on the SmartWatch. Here's how to do that: Sony SmartWatch - invoke app on Smart Watch when it gets an event

2) you also want to pass some arguments to your Extension, i.e. the String you mention. This can be a bit tricky; normally, you would pass that String in the Intent itself, as an extra, but here, that is not available. You need to save that information (the String) on a location that your Extension can access as well. So, if your Activity and your Extension are part of the same app, that location can be the app preferences: the Activity saves the value in the preferences, and the Extension reads it from the same preference and displays it on the SmartWatch or whatever.

Community
  • 1
  • 1
Eir
  • 1,003
  • 9
  • 24
  • As you suggested, using shared preferences to pass string between the App and control extension worked. I am able to send across data from my activity to the smartwatch by saving the string in prefs on onClick event of the button in the activity and retrieving it back in the onResume of my ControlExtension – Nirav Sanghvi Sep 24 '13 at 10:15
  • Thanks for accepting the answer. About your new question: you can run that code whenever you like, on start, on button click... Just note that what you wrote will work only in an emulator because of this line `intent.setPackage("com.sonyericsson.extras.liveware.emulator");` The package name would have to be specified appropriately for the SmartWatch (note also that it would be different for the SmartWatch 2). – Eir Sep 24 '13 at 19:39
0

Typically the way an extension is started is to start it from the watch and then the host app will send the broadcast to start your service.

If you are trying to start your extension from an activity the Intent above should work. Are you seeing any errors when you send that broadcast? Check that you have the right package name for the host app as well.

mldeveloper
  • 2,253
  • 1
  • 13
  • 14
  • The issue was with the Package name . When I tried running my app on the emulator by setting `"com.sonyericsson.extras.liveware.emulator" `as Package in the intent it didn't work . But I was able to run it successfully on the smart watch using `"com.sonyericsson.extras.smartwatch"` as the packagename. – Nirav Sanghvi Sep 25 '13 at 04:17