如何在oncreate android上的appodeal上创建oncreate上的广告 [英] How to show ad on oncreate from appodeal on oncreate android

查看:117
本文介绍了如何在oncreate android上的appodeal上创建oncreate上的广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,显示点击按钮的广告。

效果很好,但现在我想在应用启动时显示此广告。

我是使用appodeal,我正在使用一些代码,检查广告是否已完成加载然后显示,但它不起作用,它只适用于按钮监听器。

有人可以帮我解决这个问题问题?

我还希望展示广告后显示广告的活动。

谢谢。



我尝试过:



I have an app that shows an ad with a button click.
This works well, but now I want to show this ad on app launch.
I am using appodeal, and I am using some code, to check if the ad has finished loading and then show, but it is not working, it only works with button listener.
Can someone please help me fix this issue?
I also want the activity that shows the ad to finish after showing the ad.
Thanks.

What I have tried:

<pre>
@Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_rewarded_interstitial);
        progress = findViewById(R.id.progress);
...
//on oncreate
//This is what I have to check if the ad has finished loading, but this code 
//doesn't work and ad is only shown after button click, with a button listener.
if(progress.getProgress()==100){
            try {
                ad.show();
                Thread.sleep(3000);
                finish();
            } catch (InterruptedException e) {
                e.printStackTrace();
                finish();
            }
        }
}

推荐答案

<-- Advertisement dialog layout -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

    <ImageView

        android:id="@+id/adImageView"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        app:srcCompat="@drawable/ad1" />
</LinearLayout>







必须在setContentView方法调用之前在主应用程序的活动的OnCreate方法中实现的代码:








The code that you must implement in your main app's activity's OnCreate method prior to setContentView method invocation:


package com.epsilon.adapp;

import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final AlertDialog.Builder m_myAdDlgBuilder =
                new AlertDialog.Builder(this);

        final View myAdView = this.getLayoutInflater().
                inflate(R.layout.dialog_ad, null);

        ImageView adImageView = myAdView.findViewById(R.id.adImageView);

        adImageView.setImageDrawable(getDrawable(this.getResources().getIdentifier("ad" +
                (new Random().nextInt(3) + 1), "drawable", getPackageName())));

        m_myAdDlgBuilder.setView(myAdView);

        m_myAdDlgBuilder.setPositiveButton("ok", null);

        AlertDialog myAdDialog = m_myAdDlgBuilder.create();

        myAdDialog.setCanceledOnTouchOutside(true);

        m_myAdDlgBuilder.show();

        setContentView(R.layout.activity_main);
    }
}





以下是即用型Android项目的链接:

https://nofile.io/f/F0j207xZbn7/AdApp.zip



Here's the link to the ready-to-use Android project:
https://nofile.io/f/F0j207xZbn7/AdApp.zip


这篇关于如何在oncreate android上的appodeal上创建oncreate上的广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆