Cordova android application access Baidu mobile ssp advertising tutorial

Using Cordova to package an android application, how should I add ads? I ran into this problem recently.
I developed an application using Cordova and wanted to place ads in it to earn some tips. I found that it was not easy. Few of them provided js interfaces. Later, I found that you can insert Baidu advertisements in the application through the cordova Baidu mobile ssp plugin.

The process is as follows:
Install the cordova Baidu mobile ssp plug-in
, then download the plug-in to the local (download address https://github.com/baidumobad/baidu-ssp-cordova-plugin), after decompression, install the
cordova plugin add D:\baidu through the local path -ssp-cordova-plugin
If there is no error message after the execution of the ssp-cordova-plugin, multiple directories com.baidu.cordova.plugin.BaiduAdPlugin in the plugins directory under the project indicate that the installation is
successful . Display Baidu mobile ssp interstitial ads
in the cordova application. In the cordova application Displaying full-screen ads on Baidu Mobile SSP is slightly more complicated than banners. You need to cache and load full-screen ads first, and then showInterstitial to display ads after loading. Directly showInterstitial will not display ads. I display the ad immediately after the full-screen ad is loaded. Of course, according to the characteristics of my own application, it can be changed to show when the game is over. My js code is as follows. appID is the application ID and fullID is the full screen ad slot.
function onInterstitialReceive(message) {
     baiduAd.showInterstitial();//Display ads after loading
}
  document.addEventListener('onInterstitialReceive', onInterstitialReceive, false);//Listen to the successful event of ad loading
  baiduAd.initInterstitial("appID", "fullID");//Create an ad
  baiduAd.cacheInterstitial();//Load after creating a full screen Ad
cordova application inserts the banner advertisement of Baidu mobile advertisement Add the following js code to the js part of
the html, where appID and bannerID are the parameters applied for in the background of Baidu mobile ssp; where appID is Baidu mobile ssp (http://ssp.baidu .com), the banner ID is the banner code bit; baiduAd.AD_POSITION.BOTTOM_CENTER is the ad position, indicating that the bottom of the application is centered. There are other relative positions, you can see the constants in baiduAd.AD_POSITION.BOTTOM for details. Absolute positioning can also be used, as shown in the plugin example. For convenience I still use relative positioning.
baiduAd.initBanner("appID", "bannerID");//Initialize the banner advertisement
baiduAd.showBanner(baiduAd.AD_POSITION.BOTTOM_CENTER);//Display the advertisement in a relative position, the value of the specific relative position is in AD_POSITION


If there is a problem You can join the exchange group 475496285 and
attach the Baidu mobile advertising phonegap plug-in domestic download address
http://download.csdn.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327100376&siteId=291194637