Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InterstitialAd listener onAdClicked not working

All other listeners of InterstitialAd are working but only onAdLoaded not working.

i have set toast for all listener but onAdLoaded only not getting called but other all are working correctly.

why only onAdClicked() is not working what's wrong with this method

codes

    public class TestActivity extends AppCompatActivity {
    InterstitialAd mInterstitialAd;
    AdRequest adRequest;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity);
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-9547225037870226/6863551510");
        adRequest = new AdRequest.Builder()
                .build();
        mInterstitialAd.loadAd(adRequest);
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdFailedToLoad(int i) {
                super.onAdFailedToLoad(i);
                Toast.makeText(TestActivity.this, "ad failed to load", Toast.LENGTH_SHORT).show();


            }

            public void onAdLoaded() {
                Toast.makeText(TestActivity.this, "ad loaded", Toast.LENGTH_SHORT).show();

                showInterstitial();
            }


            @Override
            public void onAdOpened() {
                super.onAdOpened();
                Toast.makeText(TestActivity.this, "ad open", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onAdImpression() {
                super.onAdImpression();
                Toast.makeText(TestActivity.this, "ad impression", Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onAdClosed() {
                super.onAdClosed();
                Toast.makeText(TestActivity.this, "ad close", Toast.LENGTH_SHORT).show();

            }
            @Override
            public void onAdClicked() {
                super.onAdClicked();
                Toast.makeText(TestActivity.this, "ad clicked", Toast.LENGTH_SHORT).show();

            }

        });
    }
    private void showInterstitial() {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        }
    }
}
like image 304
lizzy sam Avatar asked Dec 14 '17 13:12

lizzy sam


1 Answers

onAdClicked is not intended for use with interstitial ads, and isn't invoked for them. From the documentation:

Called when a click is recorded for an ad. At the current time, this method is only used with native ads originating from Google in one of the system-defined formats (App Install or Content).

If you'd like to know when the user has clicked on an interstitial, though, you can use the onAdLeftApplication method instead. Clickthroughs will result in focus leaving the application, so it's a reliable way to know.

like image 146
RedBrogdon Avatar answered Nov 08 '22 21:11

RedBrogdon