我找到了以下内容:https://developer.android.com/reference/Randroid/support/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
做错了什么。这是我的一个看起来像(并且在起作用):
final Executor executor = new Executor() {
@Override
public void execute(@NonNull Runnable r) {
new Thread(r).start();
}
};
对我来说,就像您缺少Thread
代码。
似乎我必须使用特定的执行人:
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);