我正在使用Eclipse为android开发应用程序,我想集成Admob来赚钱。教程说我应该观看LogCat来查找ID,但是它在哪里呢?

当我在测试模式或真实模式下运行时,有时eclipse会通知广告返回,但它不会在emu中显示。有谁能解释一下吗?
发布于 2022-01-10 14:50:59
Kotlin解决方案:
要获取当前设备ID,请执行以下操作:
@SuppressLint("HardwareIds")
private fun getDeviceIdForAdMobTestAds(context: Context): String? {
val md5 = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
try {
val md = MessageDigest.getInstance("MD5")
val array = md.digest(md5.toByteArray())
val sb = StringBuilder()
for (i in array.indices)
sb.append(Integer.toHexString(array[i].toInt() and 0xFF or 0x100).substring(1, 3))
return sb.toString()
} catch (e: NoSuchAlgorithmException) {
}
return null
}用法:
val deviceIds = arrayListOf(AdRequest.DEVICE_ID_EMULATOR)
getDeviceIdForAdMobTestAds(context)?.let { deviceIds.add(it.uppercase(Locale.ROOT)) }
MobileAds.setRequestConfiguration(RequestConfiguration.Builder().setTestDeviceIds(deviceIds).build())https://stackoverflow.com/questions/4524752
复制相似问题