COCOS2DX Android Access Mango interstitial ads

Source: Internet
Author: User

Crawling through all kinds of pits, we finally have a decent little game! Then, the next job is to access the ads, on-line profit

Mango is an aggregation advertising platform, you can access the mango after the display of multi-union, Baidu, AdMob and other gray often more than the ads, very convenient.

1. Advertising platform Configuration 1.1 registered Mango account: http://www.adsmogo.com/

After entering the mango to choose App Management, add the app, fill out all kinds of information and click on the ' Add App ' button below, here the process is very simple, I will not.

Click on the app list to see the app we just added, click the app name to access the app's configuration. Here we pause, since the mango is an aggregation of advertising platform, show is another platform of advertising, then we need to apply for another platform in the same app, here we choose the multi-AU, this platform casual, we choose according to their needs, you can choose more than one.

1.2 Register multi-au: http://www.domob.cn/

Go to the multi-alliance developer backend, click My apps, add apps, and fill in the app information.

Add ad bit, and notice here that an app is a interstitial ad bit type that can have multiple ad positions.

After the success we can get the Publisher ID and ad bit ID. Here the multi-union platform is configured.

1.3 Fill in PublisherID and ad bit ID

Go back to Mango, go to the App configuration page, select fullscreen/interstitial, then click Multi-League, fill in Publisher ID and ad ID.


After saving in the priority of a tick, here the Mango platform configuration is also done ~ Note the Mango App ID, we need to access the ads.

2. Importing the SDK

First create a COCOS2DX project, make sure you can compile to Android, do not need me to introduce it (*^__^*)

Download the mango COCOS2DX version of the SDK and the multi-Union SDK to find the jar packages we need.

Open Eclipse, Import project, here I am androidtest, right-click on the Libs directory (if not libs to create a new one), select Import, General, File System, and then click Next


Find the mango and multi-Union SDK, import.


Select the two jar in the Libs folder, right-click Build path, ADD to build path.


3. Add User Rights 3.1 open Androidmanifest.xml, add the following code after the <application> tag:

<!--Add User rights--><!--Connect network rights to the Internet, requesting ads (must), Mogo will use this permission--><uses-permission android:name= " Android.permission.INTERNET "/><!--read the basic information of the phone read_phone_state, with the accurate statistics of the user's model and other information (must), Mogo will use this permission-->< Uses-permission android:name= "Android.permission.READ_PHONE_STATE"/><!--Read Network information permission Access_network_state, To identify the access point of the GPRS network (must), Mogo will use this permission--><uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE "/><!--access to the user's geographic information, use to help the poor accurate statistics of the developer's program published cookbook after the distribution of users, Mogo will use this permission--><uses-permission android:name=" Android.per Mission. Access_fine_location "/> <uses-permission android:name=" Android.permission.ACCESS_COARSE_LOCATION "/> < Uses-permission android:name= "Android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> <!--permission to read and write the SD card, By caching the images used for the ads, saving traffic and getting a better user experience, Mogo will use this permission--><uses-permission android:name= "Android.permission.WRITE_ External_storage "/><uses-permission android:name=" Android.permission.READ_EXTERNAL_STORAGE "/><!--Get the status of the current WiFi, which is required by the ad platform, Mogo will use this permission--><uses-permission android:name= "Android.permission.ACCESS_ Wifi_state "/> <!--the permissions required by the pay-as-you-use feature, Mogo uses that right--<uses-permission android:name=" Android.permission.GET_T Asks "/> <!--The requirements of the multi-League, without which the AU will not be able to display ads--><uses-permission android:name=" Android.permission.VIBRATE "/>

As shown in the following:

3.2 Declare the activity of Mogo, insert the following code in the <application> tag:

<!--statement Mogo activity--><activityandroid:name= "Com.adsmogo.adview.AdsMogoWebView" android:configchanges= "Orientation|keyboardhidden|screensize" android:label= "@string/app_name"/><activity android:name= " Com.adsmogo.mriad.view.AdsMogoActionHandler "android:configchanges=" Orientation|keyboardhidden|screensize " Android:label= "@string/app_name" ></activity><!--Registration Service, independent ads do not exchange ads for the application download function required--><service Android:name= "Com.adsmogo.controller.service.UpdateService" android:exported= "true" android:process= ": Remote"/ ><!--Register the service, install the app using--><service android:name= "Com.adsmogo.controller.service.CountService" Android: Exported= "true" android:process= ": Remote"/>
As shown in the following:


4. Embedding Ads

4.1 Add the following code to the OnCreate function in cocos2dxactivity:

<span style= "White-space:pre" ></span>adsmogointerstitialmanager.setdefaultinitmanualrefresh (false); Set Appkeyadsmogointerstitialmanager.setdefaultinitappkey ("Mogoid"); Sets the current Activity object Adsmogointerstitialmanager.setinitactivity (Cocos2dxactivity.this); Initialize (the default Appkey and activity objects must be set before the SDK can be initialized by this method) Adsmogointerstitialmanager.shareinstance (). Initdefaultinterstitial (); Handler = new Handler () {@Overridepublic void Handlemessage (Message msg) {//TODO auto-generated method Stubswitch (MSG.WH At) {Case 3:/** * Enter the opportunity * When the app needs to show a full screen ad call Interstitialshow (Boolean iswait); * Notify the SDK to enter the display time, the SDK will do its best to show the ads, of course, because the network and other issues can not be displayed immediately * Advertising, you can control the authorization SDK to display ads immediately after the ad is obtained by using the parameter iswait. */adsmogointerstitialmanager.shareinstance (). Defaultinterstitial (). Interstitialshow (True); Break;case 5:/** * Exit Opportunity * If you have previously entered the display, and the iswait parameter is set to Yes, call Method Interstitialcancel () When you need to cancel waiting for the ad's display *; notify the SDK */ Adsmogointerstitialmanager.shareinstance (). Defaultinterstitial (). Interstitialcancel (); break;default:break;}};
Replace the mogoid with the app ID you requested on the Mango platform.

4.2 Add the following three functions to the cocos2dxactivity:

<span style= "White-space:pre" ></span>//exit the show time public static void Closeinterstitial () {Message msg = Handler.obtainmessage (); msg.what = 5;handler.sendmessage (msg); }//sends a message to handler to show the full interstitial public static void Showinterstitialstatic () {log.e ("Mogococos2dx Demo", " Showinterstitialstatic "); Message msg = Handler.obtainmessage (); msg.what = 3; Handler.sendmessage (msg);} @Overrideprotected void OnDestroy () {Super.ondestroy (); Adsmogolayout.clear (); if (AdView! = null) {Adview.clearthread ();} LOG.E ("Adsmogo", "OnDestroy"); System.exit (0);}
4.3 new C + + files

Create new MOGOAd.h and MOGOAd.cpp under the classes directory.

The contents of MOGOAd.h are:

#if (Cc_target_platform = = cc_platform_android) #include <jni.h> #include "platform/android/jni/jnihelper.h" # Include <android/log.h> #endif # include "Cocos2d.h"  using namespace Cocos2d;class mogoad{public:static void Showinterstitial (); static void Closeinterstitial (); };

The contents of MOGOAd.cpp are:

#include "MOGOAd.h" void Mogoad::showinterstitial () {#if (Cc_target_platform = = cc_platform_android) jnimethodinfo Showinterstitial;bool Ishave = Jnihelper::getstaticmethodinfo (showinterstitial, "org/cocos2dx/cpp/cocos2dxactivity "," Showinterstitialstatic "," () V "); if (!ishave) {Cclog ("jni:hidebannerstatic false");} Else{cclog ("jni:hidebannerstatic true"); Showinterstitial.env->callstaticvoidmethod (ShowInterstitial.classID, Showinterstitial.methodid); } #endif}void mogoad::closeinterstitial () {#if (Cc_target_platform = = cc_platform_android) jnimethodinfo Closeinterstitial;bool Ishave = Jnihelper::getstaticmethodinfo (closeinterstitial, "org/cocos2dx/cpp/ Cocos2dxactivity "," Closeinterstitial "," () V "); if (!ishave) {Cclog ("jni:hidebannerstatic false");} Else{cclog ("jni:hidebannerstatic true"); Closeinterstitial.env->callstaticvoidmethod ( Closeinterstitial.classid, Closeinterstitial.methodid); } #endif}

4.4 Change the Click button method in HelloWorldScene.cpp to:

void Helloworld::menuclosecallback (ref* psender) {    mogoad::showinterstitial ();}

OK, merit perfection, add MOGOAd.cpp, compile, run in android.mk.



Success! Next submit the review, wait for the pass to be able to ~

COCOS2DX Android Access Mango interstitial ads

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.