1

So beforehand I made a project with Phonegap. In the Index.html file of the project I have this Button:

<button class="button" onclick="next()">Next Question</button>

Now i've imported this project into Android Studio to get it working with Admob to load interstitial ads like this:

MainActivity.java

import org.apache.cordova.*;

public class MainActivity extends CordovaActivity{
InterstitialAd mInterstitialAd;
private InterstitialAd interstitial;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // enable Cordova apps to be started in the background
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.getBoolean("cdvStartInBackground", false)){
        moveTaskToBack(true);
    }
    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    loadInterstitial();

}

public void loadInterstitial(){
    //Interstitial Intergration Part
    AdRequest adRequest = new AdRequest.Builder().build();

    //Prepare the Interstitial Ad
    interstitial = new InterstitialAd(MainActivity.this);
    // Insert the Ad Unit ID
    interstitial.setAdUnitId(getString(R.string.admob_interstitial_id));

    interstitial.loadAd(adRequest);
    //Prepare an Interstitial Ad Listener
    interstitial.setAdListener(new AdListener() {
        public void onAdLoaded(){
            //call displayInterstitial() function
            displayInterstitial();
        }
    });
}
public void displayInterstitial(){
    //If Ads are loaded, show Interstitial else show nothing.
    if (interstitial.isLoaded()){
        interstitial.show();
    }
}}

So now I want to get the loadInterstitial(); function called when the button above is pressed. Is this possible when the button is already initiated in the HTML file? if so ( or not ), can I possibly get a step in the right direction?

Thanks!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

0 Answers0