Applovin AdclickListener not working in android

2.5k views Asked by At

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.

1

There are 1 answers

2
mszaro On BEST ANSWER

The problem is that you are mixing AppLovinInterstitialAd (which internally owns its own instance of AppLovinAdView) and your own standalone AppLovinAdView. When you call AppLovinInterstitialAd.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:

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
}