Cocos2d-js added Baidu appx interstitial ad (via JSB reflex mechanism)

Source: Internet
Author: User

Originally used ANYSDK access ads, the results from a few days ago, Baidu Store audit always pass, the result of a ask only know: To upload Baidu store must use the appx (really is a variety of pits, we these personal developers sooner or later you big Company to play dead), no way can only use appx, Who is the number of Baidu is still quite big

Here is the access process:

"1" according to Baidu AppX to Appxsample, first put Libs folder under the Baidu_cuid.jar and Baidu_appx_android_2.0.0.jar two jar package copy to the project Libs inside.

"2" Copy all files under the Res folder under Appxsample to the project res, note the file merge

"3" Modify Androidmanifest.xml

Add: Activity

<!--Mobile Cloud appx SDK -        <ActivityAndroid:name= "Com.baidu.appx.ui.BDInnerBrowser" />        <receiverAndroid:name= "Com.baidu.appx.app_download.CompleteReceiver" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.DOWNLOAD_COMPLETE" />                <ActionAndroid:name= "Android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />            </Intent-filter>            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.PACKAGE_ADDED" />                <DataAndroid:scheme= "Package" />                <!--Attention!! This sentence must be added, otherwise you will not receive the installation to complete the broadcast -            </Intent-filter>        </receiver>

Add two permissions:

    <android:name= "Android.permission.WRITE_SETTINGS"/>     <android:name= "Android.permission.READ_PHONE_STATE"/>

"4" Modify the Appactivity.java file

 PackageOrg.cocos2dx.javascript;Importorg.cocos2dx.lib.Cocos2dxActivity;ImportOrg.cocos2dx.lib.Cocos2dxGLSurfaceView;ImportAndroid.content.pm.ActivityInfo;ImportAndroid.net.wifi.WifiInfo;ImportAndroid.net.wifi.WifiManager;ImportAndroid.os.Bundle;Importandroid.os.Environment;ImportAndroid.view.WindowManager;//Baidu appxImportcom.baidu.appx.BDInterstitialAd;ImportCom.baidu.appx.BDInterstitialAd.InterstitialAdListener;ImportAndroid.util.Log; Public classAppactivityextendscocos2dxactivity{//Baidu appx    Private StaticAppactivity app =NULL; Private StaticString TAG = "Appx_interstitial"; Private StaticBdinterstitialad Appxinterstitialadview; StaticString hostipadress= "0.0.0.0"; @Overrideprotected voidonCreate (Bundle savedinstancestate) {        Super. OnCreate (Savedinstancestate);
// Baidu appx app= This;//Baidu appxAppxinterstitialadview =NewBdinterstitialad ( This, "H8g8xsoysxo5ugngxdahoauw", "zqgav5gbdapwt0nwupdyls2e"); Appxinterstitialadview.setadlistener (NewInterstitialadlistener () {@Override Public voidonadvertisementdatadidloadfailure () {LOG.E (TAG,"Load Failure"); } @Override Public voidonadvertisementdatadidloadsuccess () {LOG.E (TAG,"Load Success"); } @Override Public voidOnadvertisementviewdidclick () {LOG.E (TAG,"On Click"); } @Override Public voidonadvertisementviewdidhide () {LOG.E (TAG,"On Hide"); } @Override Public voidonadvertisementviewdidshow () {LOG.E (TAG,"On show"); } @Override Public voidonadvertisementviewwillstartnewintent () {LOG.E (TAG,"Leave"); } }); Appxinterstitialadview.loadad (); } Public Static voidSDKsFinalString title,FinalString message) { //be sure to use runonuithread hereApp.runonuithread (NewRunnable () {@Override Public voidrun () {if(appxinterstitialadview.isloaded ()) {Appxinterstitialadview.showad (); } Else{log.i (TAG,"AppX interstitial Ad is isn't ready"); Appxinterstitialadview.loadad (); } } }); } }

where the SDKs () method is the JSB reflection callback method, which is intended to display interstitial advertisement

PS: To change the parameters to their own api_key and promotional bit ID

The last step of "5" is to add a method that calls SDKs () in the JS code

Jsb.reflection.callStaticMethod ("Org/cocos2dx/javascript/appactivity", "SDKs", "(ljava/lang/string; ljava/lang/string;) V "," title "," Hahahahha ");

Cocos2d-js added Baidu appx interstitial ad (via JSB reflex mechanism)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.