Android Studio - MainActivity.java中的HTML按钮

时间:2017-06-13 11:46:33

标签: java android html phonegap main-activity

所以事先我用Phonegap做了一个项目。在项目的Index.html文件中,我有这个Button:

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

现在我已将此项目导入Android Studio,以便与Admob合作加载插页式广告,如下所示:

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();
    }
}}

所以现在我想得到loadInterstitial();按下上面的按钮时调用的函数。如果已在HTML文件中启动按钮,这是否可行?如果是这样(或不是),我可以朝正确的方向迈出一步吗?

谢谢!

0 个答案:

没有答案