Start a control extension on the smart watch from my main app's Activity. Also display a text on the watch which is sent from the activity

StackOverflow https://stackoverflow.com/questions/18959831

  •  29-06-2022
  •  | 
  •  

Question

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 ?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top