4

这是在 onCreate 中:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    StartAppAd.init(this, "devID", "appID");
    setContentView(R.layout.activity_results);

    startAppAd.showAd();
    startAppAd.loadAd();
}           

它不显示广告,但如果我将其更改为:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    StartAppAd.init(this, "devID", "appID");
    setContentView(R.layout.activity_results);

    new Handler().postDelayed(new Runnable()
    {
        @Override
        public void run()
        {
            startAppAd.showAd();
            startAppAd.loadAd();
        }
    }, 2000);

}

有用。如何让广告在准备好后立即展示?

4

3 回答 3

1

I got around the problem by simply putting loadAd(); in the onCreate of the previous activity and showAd(); just before my startIntent();.

于 2013-11-06T18:12:13.947 回答
1

要显示启动应用广告,您必须按照以下步骤操作

首先声明启动应用ID

首先在 gradle 中添加此依赖项

编译'com.startapp:inapp-sdk:3.6.6'

之后在您的代码中按照您需要的这些步骤

私有 StartAppAd startAppAd = new StartAppAd(this);

在 oncreate 方法中:

    StartAppSDK.init(this, getString(R.string.startAppId), false);
    StartAppAd.disableSplash();

在字符串中,您必须传递启动应用程序 ID

如果你想显示 splash 然后不要禁用 splash 只需删除第二行

如果您想在 backpresses 上显示 startapp 广告,请按照此步骤操作

@Override
public void onBackPressed() {


    StartAppAd.onBackPressed(this);

    ExitDialogue();

}
private void ExitDialogue() {
    AlertDialog.Builder builder = new AlertDialog.Builder(SampleActivity.this);
    builder.setTitle(R.string.account_balance);
    builder.setIcon(R.mipmap.ic_launcher);
    builder.setMessage("Do you want to exit?")
            .setCancelable(false)
            .setNeutralButton("More Apps", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Future+App+Studio")));
                }
            })
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    SampleActivity.this.finish();
                    //finish();
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

如果您想在单击按钮时或在任何情况下都必须调用此方法时显示 startapp 插页式广告:

 startAppAd.loadAd(new AdEventListener() {

            @Override

            public void onReceiveAd(Ad ad) {

                startAppAd.showAd(new AdDisplayListener() {

                    @Override
                    public void adHidden(Ad ad) {
                       //implement your code here
                    }

                    @Override
                    public void adDisplayed(Ad ad) {

                    }

                    @Override
                    public void adClicked(Ad arg0) {

                    }


                    @Override
                    public void adNotDisplayed(Ad arg0) {
                        //implement your code here

                    }
                });


            }

            @Override

            public void onFailedToReceiveAd(Ad ad) {
                //implement your code here

            }


        });
于 2017-11-10T12:52:49.343 回答
1

我在另一篇文章中提到过,尝试将方法放在showAd()方法onReceiveAd()的事件监听器中loadAd()

https://stackoverflow.com/a/31959288/3835769

于 2015-08-12T08:01:23.173 回答