codingjeremy codingjeremy - 4 months ago 45
Android Question

What is the right ComponentName to use with ProviderUpdateRequester() so Android Wear 2.0 will update my complication data?

To tell the Android Wear Watch Face my complication data has been updated, I need to use the ProviderUpdateRequester() method, but it needs a ComponentName. Which is the right component name to use?


I am building a data provider for the Complications feature in Android Wear 2.0 (complications go in Watch Faces).

You can provide an update period to the system via the manifest, but I want to only update the data when there is new data.

It states in the documentation, "You can alternatively use a "push style" to send updates, rather than requesting updates on a fixed schedule. To do so, you can set the update period to 0 so scheduled update requests do not occur (or set it to a non-zero value) and use a ProviderUpdateRequester to trigger calls to onComplicationUpdate as required.".

However, it does not give a snippet of the correct ComponentName to use. I have tried this with no luck:



Here is the code you need:

ComponentName componentName =
  new ComponentName(getApplicationContext(), MyService.class);

I actually wrote a sample that demonstrates how to do this on GitHub here.

The class the does the work is class.

Here is the full code excerpt if interested:

ComponentName componentName =
  new ComponentName(getApplicationContext(), MyService.class);

ProviderUpdateRequester providerUpdateRequester = 
  new ProviderUpdateRequester(getApplicationContext(), componentName);

// This method only updates the specific complication id, you could
// update all with providerUpdateRequester.requestUpdateAll().