如何获取表盘复杂功能的提供者信息?

How to get the providerinfo for a watch face complication?

我发现了以下内容:https://developer.android.com/reference/android/support/wearable/complications/ProviderInfoRetriever.html

我尝试实现的:

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);

很遗憾,我在调试日志中没有看到任何内容:/ executor 是我做错了什么吗?

看来我必须改用特定的执行程序:

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);

是的,你的 Executor 做错了什么。这是我的其中一个的样子(并且它正在工作):

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

在我看来你缺少 Thread 代码。