如何获取表面复杂功能的providerinfo?

时间:2017-03-08 20:02:45

标签: java android wear-os android-wear-2.0

我发现了以下内容: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或其他什么地方做错了吗?

2 个答案:

答案 0 :(得分:1)

似乎我不得不使用特定的执行者:

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

答案 1 :(得分:1)

是的,您的Executor做错了。这是我的一个看起来像(并且它正在工作):

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

让我觉得你错过了Thread代码。