Android Studio获取带有官方片段的广告Id


has anyone managed to get the android advertisement Id in an app using the official snippet 
https://developer.android.com/training/articles/ad-id
I couldn't make this snippet to work in my app.
I have added the:
'''
dependencies {
implementation 'androidx.ads:ads-identifier:1.0.0-alpha01'
// Used for the calls to addCallback() in the snippets on this page.
implementation 'com.google.guava:guava:28.0-android'
}
'''
And Gradle synced without any problems.
The code that's problematic is:   

''java

ListenableFuture<AdvertisingIdInfo> advertisingIdInfoListenableFuture = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
Futures.addCallback(advertisingIdInfoListenableFuture,
new FutureCallback<AdvertisingIdInfo>() {                        
@Override
public void onSuccess(@NullableDecl AdvertisingIdInfo result) {
String myAdvertisementId = result.getId();
}
@Override
public void onFailure(Throwable t) {
}
});

"错误为:error:类Futures中的方法addCallback不能应用于给定的类型
必需:ListenableFuture、FutureCallback、Executitor

Supposedly it asks for executor but the official snippet is without one

如果您查看此处的文档,kotlin片段会传递一个Executor作为第三个参数(java示例缺少一个(。所以你应该在java:中做同样的事情

Futures.addCallback(advertisingIdInfoListenableFuture,
new FutureCallback<AdvertisingIdInfo>() {                        
@Override
public void onSuccess(@NullableDecl AdvertisingIdInfo result) {
String myAdvertisementId = result.getId();
}
@Override
public void onFailure(Throwable t) {
}
}, Executors.newSingleThreadExecutor());

最新更新