Pré-requisitos
Carregar e Mostrar o Anúncio
Considere um cenário onde o clique de um botão aciona um Interstitial e, subsequentemente, o NewActivity é lançado de MainActivity.
Carregar
# MainActivity.kt -> onCreate()
val interstitialConfigId = ConfigBuilder.INTERSTITIAL_TEST_R89_CONFIG_ID
val activityToShowOver = this
var interstitialId = RefineryAdFactory.createInterstitial(
interstitialConfigId,
activityToShowOver,
afterInterstitial = {
// Here you could load the next activity or fragment. Basically recover app flow
Log.d("Interstitial", "After Interstitial")
// Example
val newActivityIntent = Intent(activityToShowOver, NewActivity::class.java)
activityToShowOver.startActivity(newActivityIntent)
}
)
Show On Button Press
Alguns eventos acontecem em seu aplicativo, como o pressionamento de um botão, mudança de aba ou abertura de um link.
Se o Intersticial ainda não carregou ou falhou ao carregar quando você chama Mostrar, the flow will continue normally
# MainActivity.kt -> onCreate()
// Example of a button press
findViewById<Button>(<YOUR_BUTTON_ID>).setOnClickListener {
RefineryAdFactory.show(interstitialId)
}
Mostra sobre a Criação do Intersticial
Isso aumentará o tempo necessário para executar a ação do usuário.
Porque está fazendo a solicitação de anúncio quando o usuário realiza a ação. Você deve usar a abordagem anterior onde fazemos a solicitação e armazenamos o ID do anúncio para exibi-lo instantaneamente quando o usuário realiza as ações.
É assim que usamos o Interstitial que usamos em Demos.
# MainActivity.kt -> onCreate()
findViewById<Button>(<YOUR_BUTTON_ID>).setOnClickListener {
createInterstitial()
}
# MainActivity.kt
private fun createInterstitial() {
val interstitialAdId = ConfigBuilder.INTERSTITIAL_TEST_R89_CONFIG_ID
val lifecycleEvents = object : InterstitialEventListener {
/*
* We need to call show on the onLoaded event and on the OnFailedToLoad event,
* this is to show the ad in both cases so the afterInterstitial event is called
*/
override fun onLoaded() {
RefineryAdFactory.show(interstitialId)
}
override fun onFailedToLoad(error: R89LoadError) {
RefineryAdFactory.show(interstitialId)
}
// Implement other lifecycle event callbacks as needed
override fun onOpened() {
// Handle ad opened event
}
override fun onClosed() {
// Handle ad closed event
}
override fun onClicked() {
// Handle ad clicked event
}
override fun onImpression() {
// Handle ad impression event
}
}
interstitialId = RefineryAdFactory.createInterstitial(
interstitialAdId, this,
afterInterstitial = {
Log.d("Interstitial", "After Interstitial")
},
lifecycleCallbacks = lifecycleEvents
)
}
Eventos do Ciclo de Vida
You can subscribe to these events with the same method but passing a new object as a parameter. Details about this object can be found in the Reference.
OnClose is not present because we have an after interstitial event that is mandatory to pass as a parameter and holds the same functionality that OnClose with special cases.
Após Intersticial
Isso não é passado como um objeto separado como os outros Eventos porque é obrigatório lidar com o que acontece após um Intersticial ser fechado. Isso é invocado no SDK quando:
-
Tudo correu bem e o usuário acabou de fechar o anúncio em tela cheia.
-
O anúncio ainda não carregou e você tentou exibi-lo.
-
O anúncio foi invalidado e você tentou exibi-lo. Ele é invalidado quando:
-
Falha ao carregar.
-
Já mostrado.
-
Tempo demais sem mostrá-lo.
-
-
O anúncio não pôde ser exibido.