0

I've found the following: https://developer.android.com/reference/android/support/wearable/complications/ProviderInfoRetriever.html

Which I've tried to implement:

Executor executor = new Executor() {
    @Override
    public void execute(@NonNull Runnable command) {
    }
};

ProviderInfoRetriever.OnProviderInfoReceivedCallback callback = new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
    @Override
    public void onProviderInfoReceived(int i, @Nullable ComplicationProviderInfo complicationProviderInfo) {
        Log.d("MyWatchFace", complicationProviderInfo.providerName);
    }
};

ProviderInfoRetriever providerInfoRetriever = new ProviderInfoRetriever(MyWatchFaceService.this, executor);

providerInfoRetriever.init();
providerInfoRetriever.retrieveProviderInfo(callback,
        new ComponentName(
                getApplicationContext(),
                MyWatchFaceService.class)
        , COMPLICATION_IDS);

Sadly I don't see anything show up in the debug log :/ Did I do something wrong with the executor or something else?

seahorsepip
  • 4,519
  • 1
  • 19
  • 30

2 Answers2

1

Seems I had to use a specific executor instead:

Executor executor = Executors.newSingleThreadExecutor();

ProviderInfoRetriever.OnProviderInfoReceivedCallback callback = new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
    @Override
    public void onProviderInfoReceived(int i, @Nullable ComplicationProviderInfo complicationProviderInfo) {
        Log.d("MyWatchFace", complicationProviderInfo.providerName);
    }
};

ProviderInfoRetriever providerInfoRetriever = new ProviderInfoRetriever(getApplicationContext(), executor);

providerInfoRetriever.init();
providerInfoRetriever.retrieveProviderInfo(callback,
        new ComponentName(
                getApplicationContext(),
                MyWatchFaceService.class)
        , COMPLICATION_IDS);
seahorsepip
  • 4,519
  • 1
  • 19
  • 30
1

Yes, you have done something wrong with your Executor. Here's what one of mine looks like (and it's working):

final Executor executor = new Executor() {
            @Override
            public void execute(@NonNull Runnable r) {
                new Thread(r).start();
            }
        };

Looks to me like you're missing the Thread code.

Sterling
  • 6,365
  • 2
  • 32
  • 40
  • Is this better then `Executor.newSingleThreadExecutor()` ? The code is being called in the onCreate method of an activity. – seahorsepip Mar 10 '17 at 16:36
  • 1
    I wouldn't think there's any functional difference. According to the docs, `Executors.newSingleThreadExecutor()` "Creates an Executor that uses a single worker thread", which is more or less the same thing that my code is doing. I assume the version from your own answer is working? – Sterling Mar 10 '17 at 17:52