I am integrating AppLovin sdk to integrate ads in my app.My app is a game app and I want my user to reward coins when they click on the ads.But adclicklistener of AppLovin seems not working in my case.
The Code:
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);
}
}
});
The INTERSTITIAL ad is displaying but the click listener is not working.
The problem is that you are mixing
AppLovinInterstitialAd
(which internally owns its own instance ofAppLovinAdView
) and your own standaloneAppLovinAdView
. When you callAppLovinInterstitialAd.show()
, you're bypassing your ad view which had the listener attached to it.So you don't need to use
AppLovinAdView
at all... give this a try: