我正在整合 AppLovin sdk 以在我的应用中集成广告。我的应用是一个游戏应用,我希望我的用户在点击广告时奖励硬币。但AppLovin的adclicklistener似乎无法正常工作就我而言。
守则:
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广告正在显示,但点击监听器无效。
答案 0 :(得分:1)
问题在于,您正在混合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
}