Мне не удалось загрузить объявление: 3.
Я уже пробовал с запросом согласия от европейских пользователей. Но это не работает, я уже жду 7 дней.
class MainActivity{
lateinit var mAdView: AdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getUserConsent()
}
@SuppressLint("HardwareIds")
private fun getUserConsent() {
try {
if (!isConsentYet) {
val msg = "Your privacy policy"
@SuppressLint("InflateParams")
val view = LayoutInflater.from(this@MainActivity)
.inflate(R.layout.dialog_consent, null, false)
val d = AlertDialog.Builder(this)
.setView(view)
.setCancelable(false)
.setTitle("User Consent")
.setIcon(R.mipmap.ic_launcher)
.create()
view.txtAlertMsg.text = Html.fromHtml(msg)
view.btnAccept.setOnClickListener {
ConsentInformation.getInstance(this@MainActivity).addTestDevice(
Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
)
)
ConsentInformation.getInstance(this@MainActivity).consentStatus =
if (view.chkGDPR.isChecked)
ConsentStatus.PERSONALIZED else ConsentStatus.NON_PERSONALIZED
isConsentYet = true
d.dismiss()
loadAds()
}
d.show()
setTextViewHTML(view.txtAlertMsg, msg)
} else {
loadAds()
}
} catch (e: Exception) {
e.printStackTrace()
}
}
protected fun setTextViewHTML(text: TextView, html: String) {
val sequence = Html.fromHtml(html)
val strBuilder = SpannableStringBuilder(sequence)
val urls = strBuilder.getSpans(0, sequence.length,
URLSpan::class.java)
for (span in urls) {
makeLinkClickable(strBuilder, span)
}
text.text = strBuilder
text.movementMethod = LinkMovementMethod.getInstance()
}
protected fun makeLinkClickable(strBuilder:
SpannableStringBuilder, span: URLSpan) {
val start = strBuilder.getSpanStart(span)
val end = strBuilder.getSpanEnd(span)
val flags = strBuilder.getSpanFlags(span)
val clickable = object : ClickableSpan() {
override fun onClick(view: View) {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse("Privacy URL")
startActivity(i)
}
}
strBuilder.setSpan(clickable, start, end, flags)
strBuilder.removeSpan(span)
}
private fun loadAds() {
mAdView = findViewById(R.id.adView)
MobileAds.initialize(this, getString(R.string.app_id))
val adRequest = AdRequest.Builder().build()
val adView = AdView(this)
adView.adSize = AdSize.BANNER
adView.adUnitId = getString(R.string.ad_bottom)
mAdView.loadAd(adRequest)
mAdView.adListener = object : AdListener() {
override fun onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.w("AdListener", "onAdLoaded")
}
override fun onAdFailedToLoad(errorCode: Int) {
// Code to be executed when an ad request fails.
Log.w("AdListener",
"onAdFailedToLoad".plus(errorCode))
}
override fun onAdOpened() {
// Code to be executed when an ad opens an overlay
that
// covers the screen.
Log.w("AdListener", "onAdOpened")
}
override fun onAdClicked() {
// Code to be executed when the user clicks on an ad.
Log.w("AdListener", "onAdClicked")
}
override fun onAdLeftApplication() {
// Code to be executed when the user has left the app.
Log.w("AdListener", "onAdLeftApplication")
}
override fun onAdClosed() {
// Code to be executed when the user is about to
return
// to the app after tapping on an ad.
Log.w("AdListener", "onAdClosed")
}
}
}
Всегда, я получаю ERROR_CODE_NO_FILL через несколько дней.