0

I would like to send some data (string) from Android application to my Smartwatch extension.

I create an Intent in my Main Activity and send it using startService().

From that I understand, I have to override onStartCommand() in a class that extends ExtensionService.

My question is how my class that extends ControlExtension will be notify of this Intent ?

Thanks in advance

user2202087
  • 49
  • 1
  • 1
  • 8

1 Answers1

2

Your best option is to use a broadcast receiver. Register a receiver in your control and filter for the intent you send. (Instead of calling startService you should send your intent as a broadcast).

You can create and broadcast your intent with

Intent intent = new Intent("my.super.cool.intent.name");
sendBroadcast(intent)

and then filter with:

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("my.super.cool.intent.name");
AlexanderNajafi
  • 1,631
  • 2
  • 25
  • 39
  • Tell me if I'm wrong, but if I understand correctly my class that extends BroadcastReceiver should filter the intent and setClass to my controlExtension. Which method should I use to coolect my intent in my controlExtension ? If by chance you have an example it will be great =) – user2202087 Jul 04 '14 at 12:08
  • Thanks =) It works perfectly. I just have a new (and quick) question. I don't need (so far) to have a class that extends ExtensionService ? – user2202087 Jul 04 '14 at 13:39
  • Yes you do, you need the service. Its used for many different things. For example it is vital in the registration process of the extension. – AlexanderNajafi Jul 04 '14 at 13:44