質問編集履歴
1
内容の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【Android】広告ID
|
1
|
+
【Android】端末識別の為に広告IDを取得したい
|
test
CHANGED
@@ -67,3 +67,81 @@
|
|
67
67
|
公告IDが取得できない原因には何があるでしょうか。
|
68
68
|
|
69
69
|
どなたか教えてくださると助かります。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
### 試したこと
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
[https://developer.android.com/training/articles/ad-id?hl=ja](https://developer.android.com/training/articles/ad-id?hl=ja)
|
78
|
+
|
79
|
+
こちらのページを参考に、以下のようにコードを書いてみましたが、良い結果は得られませんでした。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```Kotlin
|
84
|
+
|
85
|
+
private fun determineAdvertisingInfo() {
|
86
|
+
|
87
|
+
if (AdvertisingIdClient.isAdvertisingIdProviderAvailable(this)) {
|
88
|
+
|
89
|
+
val advertisingIdInfoListenableFuture = AdvertisingIdClient.getAdvertisingIdInfo(applicationContext)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
addCallback(advertisingIdInfoListenableFuture,
|
94
|
+
|
95
|
+
object : FutureCallback<AdvertisingIdInfo> {
|
96
|
+
|
97
|
+
override fun onSuccess(adInfo: AdvertisingIdInfo?) {
|
98
|
+
|
99
|
+
val id: String = adInfo!!.id
|
100
|
+
|
101
|
+
val providerPackageName: String = adInfo.providerPackageName
|
102
|
+
|
103
|
+
val isLimitTrackingEnabled: Boolean = adInfo.isLimitAdTrackingEnabled
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
println("広告ID:$id")
|
108
|
+
|
109
|
+
println(providerPackageName)
|
110
|
+
|
111
|
+
println(isLimitTrackingEnabled)
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
override fun onFailure(t: Throwable) {
|
118
|
+
|
119
|
+
Log.e("MY_APP_TAG",
|
120
|
+
|
121
|
+
"Failed to connect to Advertising ID provider.")
|
122
|
+
|
123
|
+
// Try to connect to the Advertising ID provider again, or fall
|
124
|
+
|
125
|
+
// back to an ads solution that doesn't require using the
|
126
|
+
|
127
|
+
// Advertising ID library.
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
}, Executors.newSingleThreadExecutor())
|
132
|
+
|
133
|
+
} else {
|
134
|
+
|
135
|
+
println("広告ID:使用できない")
|
136
|
+
|
137
|
+
// The Advertising ID client library is unavailable. Use a different
|
138
|
+
|
139
|
+
// library to perform any required ads use cases.
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
```
|