Сомнения в реализации SDK платформы обмена сообщениями пользователей для Android
Я хочу внедрить SDK платформы обмена сообщениями пользователей для Android. Первое, что я делаю, это следую руководству https://developers.google.com/admob/ump/android/quick-start , но есть несколько вещей, которые я не понимаю из примера.
Код в руководстве выглядит так (на kotlin, но без конвертации лямбда-выражений):
class MyActivity : AppCompatActivity() {
private lateinit var consentInformation: ConsentInformation
private lateinit var consentForm: ConsentForm
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val params = ConsentRequestParameters.Builder()
.setTagForUnderAgeOfConsent(false)
.build()
consentInformation = UserMessagingPlatform.getConsentInformation(this)
consentInformation.requestConsentInfoUpdate(this, params,
object : ConsentInformation.OnConsentInfoUpdateSuccessListener{
override fun onConsentInfoUpdateSuccess() {
if (consentInformation.isConsentFormAvailable) {
loadForm()
}
}
},
object : ConsentInformation.OnConsentInfoUpdateFailureListener{
override fun onConsentInfoUpdateFailure(formError: FormError) {
Log.e("AdmobUserConsent","onConsentInfoUpdateFailure ${formError.message}")
}
}
)
}
private fun loadForm() {
UserMessagingPlatform.loadConsentForm(
this,
object : UserMessagingPlatform.OnConsentFormLoadSuccessListener{
override fun onConsentFormLoadSuccess(mconsentForm: ConsentForm) {
consentForm = mconsentForm
if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) {
mconsentForm.show(
this@MyActivity,
object : ConsentForm.OnConsentFormDismissedListener {
override fun onConsentFormDismissed(formError: FormError?) {
loadForm()
}
}
)
}
}
},
object : UserMessagingPlatform.OnConsentFormLoadFailureListener{
override fun onConsentFormLoadFailure(formError: FormError) {
Log.e("AdmobUserConsent","onConsentFormLoadFailure ${formError.message}")
}
}
)
}
}
Почему проверяется после ? Почему проверяется даже после запроса формы с ?
Этот пример кода всегда вызывает обе эти функции, даже если они уже
OBTAINED
.
я не понимаю почему
ConsentStatus
не проверяется перед
requestConsentInfoUpdate()
и до
loadConsentForm()
чтобы не делать ненужных звонков. Я что-то упускаю?
Кроме того, почему
loadForm()
снова позвонил в
onConsentFormDismissed()
?
Мой код будет (простите за форматирование):
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val params = ConsentRequestParameters.Builder()
.setTagForUnderAgeOfConsent(false)
.build()
val consentInformation = UserMessagingPlatform.getConsentInformation(this)
if (consentInformation.consentStatus in listOf(ConsentInformation.ConsentStatus.REQUIRED,ConsentInformation.ConsentStatus.UNKNOWN)){
consentInformation.requestConsentInfoUpdate(this, params,{
if (consentInformation.isConsentFormAvailable) {
UserMessagingPlatform.loadConsentForm(
this,
{ consentForm ->
if (consentInformation.consentStatus in listOf(ConsentInformation.ConsentStatus.REQUIRED,ConsentInformation.ConsentStatus.UNKNOWN)) { // <- Maybe ConsentStatus is never UNKNOWN after requestConsentInfoUpdate
consentForm.show(this@MyActivity) {
it?.let { Log.e("AdmobUserConsent", "OnConsentFormDismissedListener ${it.message}") }
}
}
}
) { Log.e("AdmobUserConsent", "onConsentFormLoadFailure ${it.message}") }
}
})
{ Log.e("AdmobUserConsent", "onConsentInfoUpdateFailure ${it.message}") }
}
}
}
Этот код в порядке или, извините за повторный вопрос, я что-то упустил из примера кода?
Спасибо