質問編集履歴
1
内容の修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
【Android】広告ID
|
1
|
+
【Android】端末識別の為に広告IDを取得したい
|
body
CHANGED
@@ -32,4 +32,43 @@
|
|
32
32
|
|
33
33
|
このように書いてテストしたところ、『 広告ID: 』というふうに表示されました。
|
34
34
|
公告IDが取得できない原因には何があるでしょうか。
|
35
|
-
どなたか教えてくださると助かります。
|
35
|
+
どなたか教えてくださると助かります。
|
36
|
+
|
37
|
+
### 試したこと
|
38
|
+
|
39
|
+
[https://developer.android.com/training/articles/ad-id?hl=ja](https://developer.android.com/training/articles/ad-id?hl=ja)
|
40
|
+
こちらのページを参考に、以下のようにコードを書いてみましたが、良い結果は得られませんでした。
|
41
|
+
|
42
|
+
```Kotlin
|
43
|
+
private fun determineAdvertisingInfo() {
|
44
|
+
if (AdvertisingIdClient.isAdvertisingIdProviderAvailable(this)) {
|
45
|
+
val advertisingIdInfoListenableFuture = AdvertisingIdClient.getAdvertisingIdInfo(applicationContext)
|
46
|
+
|
47
|
+
addCallback(advertisingIdInfoListenableFuture,
|
48
|
+
object : FutureCallback<AdvertisingIdInfo> {
|
49
|
+
override fun onSuccess(adInfo: AdvertisingIdInfo?) {
|
50
|
+
val id: String = adInfo!!.id
|
51
|
+
val providerPackageName: String = adInfo.providerPackageName
|
52
|
+
val isLimitTrackingEnabled: Boolean = adInfo.isLimitAdTrackingEnabled
|
53
|
+
|
54
|
+
println("広告ID:$id")
|
55
|
+
println(providerPackageName)
|
56
|
+
println(isLimitTrackingEnabled)
|
57
|
+
}
|
58
|
+
|
59
|
+
override fun onFailure(t: Throwable) {
|
60
|
+
Log.e("MY_APP_TAG",
|
61
|
+
"Failed to connect to Advertising ID provider.")
|
62
|
+
// Try to connect to the Advertising ID provider again, or fall
|
63
|
+
// back to an ads solution that doesn't require using the
|
64
|
+
// Advertising ID library.
|
65
|
+
}
|
66
|
+
}, Executors.newSingleThreadExecutor())
|
67
|
+
} else {
|
68
|
+
println("広告ID:使用できない")
|
69
|
+
// The Advertising ID client library is unavailable. Use a different
|
70
|
+
// library to perform any required ads use cases.
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
```
|