要显示启动应用广告,您必须按照以下步骤操作
首先声明启动应用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
}
});