如何在应用启动时显示admob插页式广告 [英] how to show admob interstitial on app start

查看:426
本文介绍了如何在应用启动时显示admob插页式广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助
如何在应用启动时显示admob插页式广告
i想在应用启动
时触发admon插页式记录,我的应用是滑动标签内容
我需要任何解决方案
任何人都有一个想法

I need help how to show admob interstitial on app start i want to trigger the admon interstitial when app launched for the record my app is a swipe tab content Pleas i need any solution any one have an idea

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    private InterstitialAd interstitial;

    private ViewPager viewPager;
    private TabsPagerAdapter mAdapter;
    private ActionBar actionBar;
    // Tab titles


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("");

        //google ads Banner
        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        ActionBar actionBar = getActionBar();

        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("ca-app-pub-1417847946178022/7723890794");

        // Create ad request.
        adRequest = new AdRequest.Builder().build();

        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);


        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }

        /**
         * on swiping the viewpager make respective tab selected
         * */
        final ActionBar finalActionBar = actionBar;
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // on changing the page
                // make respected tab selected
                finalActionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });




        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
                displayInterstitial();
            }
        });


    }

    // Invoke displayInterstitial() when you are ready to display an interstitial.
    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }


    }


    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // on tab selected
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }


}


推荐答案

请注意,根据禁止执行admob


应用加载或退出

App load or exit

请勿在应用加载时放置插页式广告,退出应用时应将插页式广告仅放置在应用内容页面之间。

Do not place interstitial ads on app load and when exiting apps as interstitials should only be placed in between pages of app content.

不遵守此政策可能会导致您的应用广告无法投放。

Failure to adhere to this policy might lead to the disabling of ad-serving to your app.

如果您仍然希望这样做,则可以在 onResume的方法中显示:

If you still want this, you can display in your onResume's method:

boolean isAdShown;

@Override
protected void onResume() {
    super.onResume();
    if (!isAdShown) {
        displayInterstitial();
        isAdShown = true;
    }
}

这篇关于如何在应用启动时显示admob插页式广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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