我正在整合AppLovin sdk以将广告整合到我的应用程序中。我的应用程序是游戏应用程序,我希望用户点击广告时奖励硬币。
代码:
private AppLovinAdView adView;
// Create AppLovin Ad View
final AppLovinSdk sdk = AppLovinSdk.getInstance(SceneActivity.this);
adView = new AppLovinAdView(sdk, AppLovinAdSize.INTERSTITIAL, SceneActivity.this);
//Show ad after 4 levels
if (currentLevel % 4 == 0) {
// An ad is available to display. It's safe to call show.
AppLovinInterstitialAd.show(SceneActivity.this);
adView.loadNextAd();
}
adView.setAdClickListener(new AppLovinAdClickListener() {
@SuppressLint("SimpleDateFormat")
@Override
public void adClicked(AppLovinAd arg0)
{
System.out.println("Adclicked");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String today = sdf.format(new Date());
if (!today.equalsIgnoreCase(getLastDownloadDate())) {
// give coins once per day
modifyMoney(MONEY_DOWNLOAD_GAME);
// put last Download date
setLastDownloadDate(today);
}
}
});
INTERSTITIAL广告正在显示,但点击侦听器不起作用。
最佳答案
问题在于您正在混合AppLovinInterstitialAd
(内部拥有自己的AppLovinAdView
实例)和自己的独立AppLovinAdView
。调用AppLovinInterstitialAd.show()
时,您将绕过附加了侦听器的广告视图。
因此,您根本不需要使用AppLovinAdView
...试试看:
private void showInterstitial() {
final AppLovinSdk sdk = AppLovinSdk.getInstance(mActivity);
final AppLovinInterstitialAdDialog adDialog = AppLovinInterstitialAd.create(sdk, mActivity);
adDialog.setAdClickListener(new AppLovinAdClickListener() {
@Override
public void adClicked(AppLovinAd appLovinAd) {
// Ad clicked, add your on-click logic here
}
});
adDialog.show(); // Display a pre-cached interstitial
}