相比于百度广告的SDK,有米广告的植入就很简单了,因为有米提供的有cocos2d-x的demo,基本上就是看着文档的流程,照着demo写自己的代码。

【申请发布ID和应用密钥,下载SDK】

1.上传应用,获取有米提供的发布ID和应用密钥

2.在有米官网下载cocos2d-x的demo

3.将自己项目的android版本导入到eclipse中



准备工作做好了,现在开始正式操作了。


【导入有米提供的jar,配置】

在下载的demo中找到YoumiSdk_v5.00_2015-01-08.jar文件,将它导入到自己项目的libs文件夹中



之后右键选择 Build Path 再选择 Add to Build Path ,将jar导入到项目中。



完成之后,下图红圈内会有显示



接下来,配置AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.richard.Zodiac"	<!-- 自己的包名 -->
      android:versionCode="1"
      android:versionName="1.0"
      android:installLocation="auto">

    <uses-sdk android:minSdkVersion="9"/>
    <uses-feature android:glEsversion="0x00020000" />

    <uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.READ_PHONE_STATE" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.GET_TASKS" />
	<!-- 以下为可选权限 -->
	<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
	<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
    <application android:label="@string/app_name"
                 android:icon="@drawable/icon">
					 
        <!-- Tell Cocos2dxActivity the name of our .so -->
        <Meta-data android:name="android.app.lib_name"
	              android:value="cocos2dcpp" />

        <activity android:name="org.cocos2dx.cpp.AppActivity"
                  android:label="@string/app_name"
                  android:screenorientation="portrait"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:configChanges="orientation">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
                 <!-- 有米必备组件配置 -->
        <activity
            android:name="net.youmi.android.Adbrowser"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:screenorientation="portrait"
            android:theme="@android:style/Theme.Light.NoTitleBar" >
        </activity>

        <service
            android:name="net.youmi.android.AdService"
            android:exported="false" >
        </service>

        <receiver android:name="net.youmi.android.AdReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <!-- 有米积分广告所需组件 -->
        <service
            android:name="net.youmi.android.ExpService"
            android:exported="false" >
        </service>

        <!-- (可选)设置有米广告推广渠道号(这里替换为非负整数的渠道号),参数列表:http://wiki.youmi.net/Wiki/PromotionChannelIDs -->
        <Meta-data
            android:name="YOUMI_CHANNEL"
            android:value="10360" >		<!-- 上线渠道号 -->
        </Meta-data>
        
    </application>

    <supports-screens android:anyDensity="true"
                      android:smallScreens="true"
                      android:normalScreens="true"
                      android:largeScreens="true"
                      android:xlargeScreens="true"/>

    <uses-permission android:name="android.permission.INTERNET"/>
</manifest> 

这里需要注意,渠道号要对应上线渠道。比如我在腾讯上线,渠道号是10360。


之后就是代码了,先写Java代码,再写C++代码。


有米提供三种广告形式,Banner广告,插屏广告,还有积分墙。


实际操作中可以选择其中的一种或几种,这里,我选择全部使用


【Java代码】

/****************************************************************************
copyright (c) 2008-2010 Ricardo Quesada
copyright (c) 2010-2012 cocos2d-x.org
copyright (c) 2011      Zynga Inc.
copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted,free of charge,to any person obtaining a copy
of this software and associated documentation files (the "Software"),to deal
in the Software without restriction,including without limitation the rights
to use,copy,modify,merge,publish,distribute,sublicense,and/or sell
copies of the Software,and to permit persons to whom the Software is
furnished to do so,subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,fitness FOR A PARTIculaR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR copYRIGHT HOLDERS BE LIABLE FOR ANY CLaim,damAGES OR OTHER
LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.cpp;


import net.youmi.android.AdManager;
import net.youmi.android.banner.AdSize;
import net.youmi.android.banner.AdView;
import net.youmi.android.banner.AdViewListener;
import net.youmi.android.listener.Interface_ActivityListener;
import net.youmi.android.offers.OffersManager;
import net.youmi.android.offers.OffersWallDialogListener;
import net.youmi.android.offers.PointsChangeNotify;
import net.youmi.android.offers.PointsManager;
import net.youmi.android.spot.SpotDialogListener;
import net.youmi.android.spot.SpotManager;

import org.cocos2dx.lib.Cocos2dxActivity;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

public class AppActivity extends Cocos2dxActivity implements PointsChangeNotify {

	// 以下常量为各种功能的标识,值随意起
	private final static int SHOW_SPOT_AD = 100;

	private final static int SHOW_BANNER = 102;

	private final static int HIDE_BANNER = 103;

	private final static int SHOW_OFFER_WALL = 200;

	private final static int SHOW_OFFER_WALL_DIALOG = 201;

	private final static int QUERY_POINTS = 202;

	private final static int AWARD_POINTS = 203;

	private final static int SPEND_POINTS = 204;

	/**
	 * 无积分Banner
	 */
	private AdView mBannerView;

	private LinearLayout mBannerLayout;

	private static Handler handler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 初始化接口,应用启动的时候调用,参数:appId,appSecret,是否开启调试模式
		AdManager.getInstance(this).init("f7d12635a71a5015","b97bb08fe2496d5e",false);

		// (可选)开启用户数据统计服务,(sdk v4.08之后新增功能)默认不开启,传入false值也不开启,只有传入true才会调用
		AdManager.getInstance(this).setUserDataCollect(true);

		// --------------------------------------------------------------------------------
		// 积分广告初始化及相关设置
		// 如果使用积分广告,请务必调用积分广告的初始化接口:
		OffersManager.getInstance(this).onAppLaunch();

		// (可选)注册积分监听-随时随地获得积分的变动情况
		PointsManager.getInstance(this).registerNotify(this);

		// --------------------------------------------------------------------------------
		// 插屏接口初始化及相关设置
		// (建议使用)预加载插播资源
		SpotManager.getInstance(this).loadSpotAds();

		// (可选) 设置插屏图片为横屏
		SpotManager.getInstance(this).setSpotOrientation(
				SpotManager.ORIENTATION_PORTRAIT);

		// (可选) 设置插屏广告动画效果为高级动画效果
		SpotManager.getInstance(this).setAnimationType(SpotManager.ANIM_ADVANCE);

		// --------------------------------------------------------------------------------
		initHandler();

	}

	@Override
	protected void onDestroy() {
		// (可选)注销积分监听
		// 如果在onCreate调用了PointsManager.getInstance(this).registerNotify(this)进行积分余额监听器注册,那这里必须得注销
		PointsManager.getInstance(this).unRegisterNotify(this);

		// 回收积分广告占用的资源
		OffersManager.getInstance(this).onAppExit();

		// 回收插屏广告占用的资源
		SpotManager.getInstance(this).onDestroy();
		super.onDestroy();
	}

	@Override
	protected void onStop() {
		// 如果不调用此方法,则按home键的时候会出现图标无法显示的情况。
		SpotManager.getInstance(this).onStop();
		super.onStop();
	}

	private void initHandler() {
		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				// Todo Auto-generated method stub

				switch (msg.what) {
				case SHOW_SPOT_AD:
					// 展示插屏广告
					SpotManager.getInstance(AppActivity.this).showSpotAds(
							AppActivity.this,new SpotDialogListener() {

								@Override
								public void onShowSuccess() {
									//showTipsInUiThread("插屏广告展示成功",Toast.LENGTH_SHORT);
								}

								@Override
								public void onShowFailed() {
									//showTipsInUiThread("插屏广告展示失败\n原因请查看Logcat-tag:YoumiSdk",Toast.LENGTH_LONG);
								}

								@Override
								public void onSpotClosed() {
									//showTipsInUiThread("插屏广告关闭了",Toast.LENGTH_SHORT);
								}

							});
					break;
				case SHOW_BANNER:
					if (mBannerView == null) {

						// 实例化广告条
						mBannerView = new AdView(AppActivity.this,AdSize.FIT_SCREEN);
						mBannerView.setAdListener(new AdViewListener() {

							@Override
							public void onSwitchedAd(AdView arg0) {
								//showTipsInUiThread("广告条切换广告了",Toast.LENGTH_SHORT);
							}

							@Override
							public void onReceivedAd(AdView arg0) {
								//showTipsInUiThread("广告条接收到广告了",Toast.LENGTH_SHORT);
							}

							@Override
							public void onFailedToReceivedAd(AdView arg0) {
								//showTipsInUiThread("广告条展示失败",Toast.LENGTH_LONG);
							}
						});
						// 创建布局来承载广告条
						if (mBannerLayout == null) {
							mBannerLayout = new LinearLayout(AppActivity.this);
							mBannerLayout.setLayoutParams(new LinearLayout.LayoutParams(
									LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
							mBannerLayout.addView(mBannerView);
						}
						// 采用WindowManager来进行
						WindowManager mWindowManager = (WindowManager) getContext().getSystemService(
								Context.WINDOW_SERVICE);
						WindowManager.LayoutParams mWmParams = new WindowManager.LayoutParams();
						mWmParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
								| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
						mWmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
						mWmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
						mWmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
						mWmParams.alpha = 1.0F;
						mWmParams.format = 1;
						mWmParams.gravity = Gravity.BottOM | Gravity.RIGHT; // 这里示例为:在右下角展示广告条条
						mWindowManager.addView(mBannerLayout,mWmParams);
					}
					break;
				case HIDE_BANNER:
					if (mBannerLayout != null) {
						((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
								.removeView(mBannerLayout);
						mBannerLayout = null;
						mBannerView = null;
					} else {
						//showTipsInUiThread("当前广告条没有展示",Toast.LENGTH_SHORT);
					}
					break;
				case SHOW_OFFER_WALL:
					// 展示积分墙全屏对话框
					OffersManager.getInstance(AppActivity.this).showOffersWall(
							new Interface_ActivityListener() {

								@Override
								public void onActivityDestroy(Context context) {
									// Todo Auto-generated method stub
									//showTipsInUiThread("全屏积分墙退出了",Toast.LENGTH_LONG);
								}
							});
					break;
				case SHOW_OFFER_WALL_DIALOG:
					// 积分墙对话框支持多种重载,详情请查看文档
					OffersManager.getInstance(AppActivity.this).showOffersWallDialog(
							AppActivity.this,new OffersWallDialogListener() {

								@Override
								public void onDialogClose() {
									//showTipsInUiThread("积分墙对话框关闭了",Toast.LENGTH_SHORT);
								}
							});
					break;

				default:
					break;
				}

				super.handleMessage(msg);
			}
		};
	}

	/**
	 * 展示插屏广告
	 */
	public static void showSpotAd() {
		sendMsgToHandler(SHOW_SPOT_AD);
	}

	/**
	 * 关闭插屏广告
	 * 
	 * @return true : 什么都不做<br>
	 *         false : 执行开发者写好的关闭插屏广告后的逻辑
	 */
	public static boolean closeSpotAd() {
		return SpotManager.getInstance(getContext()).disMiss();
	}

	/**
	 * 展示广告条
	 */
	public static void showBanner() {
		sendMsgToHandler(SHOW_BANNER);
	}

	/**
	 * 隐藏广告条
	 */
	public static void hideBanner() {
		sendMsgToHandler(HIDE_BANNER);
	}

	/**
	 * 展示全屏积分墙
	 */
	public static void showOfferWall() {
		sendMsgToHandler(SHOW_OFFER_WALL);
	}

	/**
	 * 展示对话框积分墙
	 */
	public static void showOfferWallDialog() {
		sendMsgToHandler(SHOW_OFFER_WALL_DIALOG);
	}

	/**
	 * 查询积分
	 * 
	 * @return 整形积分值
	 */
	public static int queryPoints() {
		return PointsManager.getInstance(getContext()).queryPoints();
	}

	/**
	 * 奖励积分
	 * 
	 * @param points
	 *            奖励的积分
	 * @return 操作是否成功
	 */
	public static boolean awardPoints(int points) {
		return PointsManager.getInstance(getContext()).awardPoints(points);
	}

	/**
	 * 消耗积分
	 * 
	 * @param points
	 *            消耗的积分
	 * @return 操作是否成功
	 */
	public static boolean spendPoints(int points) {
		return PointsManager.getInstance(getContext()).spendPoints(points);
	}

	/**
	 * 积分余额变动通知,当用户的积分发生变动(增加或者减少)时,会回调本方法,本方法执行在UI线程中
	 */
	@Override
	public void onPointBalanceChange(int points) {
		// Todo Auto-generated method stub
		//showTipsInUiThread("积分余额发生变动了,当前积分:" + points,Toast.LENGTH_SHORT);

		// 积分增加或者减少,可以通过下面的函数在C++进行一些操作,如提示积分不足等。
		pointsBalanceChange(points);
	}

	/**
	 * 定义JAVA本地函数,通过本地函数,调用C++的代码
	 * 
	 * @param point
	 * @return
	 */
	private native int pointsBalanceChange(int points);

	private synchronized static void sendMsgToHandler(int type) {
		Message msg = handler.obtainMessage();
		msg.what = type;
		msg.sendToTarget();
	}

	public static void showTipsInUiThread(final String str,final int duartion) {
		handler.post(new Runnable() {

			@Override
			public void run() {
				Toast.makeText(getContext(),str,duartion).show();
			}
		});
	}
}


代码都是从demo中copy过来的,需要注意的是

1.

AdManager.getInstance(this).init("f7d12635a71a5015",false);
这里要使用自己在有米获取的 发布ID和应用密钥


2.

public static void showTipsInUiThread(final String str,duartion).show();
			}
		});
	}

这个函数在测试的时候用着很方便,发布的时候可以把它去下来。

【C++部分】

通过jni实现C++层和Java层互相调用,其原理可以查看官网文档

回到C++层,在我们项目的Classes目录下,自定义一个类,这里我建了名为AdHelp.h和AdHelp.cpp的文件


AdHelp.h

/*
************************************************************************
*
*	AdHelp.h
*	Author: 
*       describe: 插广告
*
************************************************************************
*/

#ifndef __AdHelp__H__
#define __AdHelp__H__

#include <cocos2d.h>
using namespace cocos2d;

#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include <android/log.h>

#endif

class AdHelp
{
public:

	AdHelp();
	virtual ~AdHelp();

	// -------------------------------------------------------------
	// 无积分广告使用
	static void showSpotAd();           //通过JNI调用JAVA静态函数,实现展示插屏广告
	static bool closeSpotAd();          //通过JNI调用JAVA静态函数,实现关闭插屏广告
	static void showBanner();           //通过JNI调用JAVA静态函数,实现展示广告条
	static void hideBanner();           //通过JNI调用JAVA静态函数,实现隐藏广告条

	// -------------------------------------------------------------
	// 积分广告使用
	static void showOfferWall();        //通过JNI调用JAVA静态函数,实现展示积分墙(全屏)
	static void showOfferWallDialog();  //通过JNI调用JAVA静态函数,实现展示积分墙(对话框)
	static int queryPoints();           //通过JNI调用JAVA静态函数,实现查询当前积分
	static bool awardPoints(int points);//通过JNI调用JAVA静态函数,实现增加积分
	static bool spendPoints(int points);//通过JNI调用JAVA静态函数,实现消耗积分
};

#endif


AdHelp.cpp

/*
************************************************************************
*
*	AdHelp.cpp
*	Author: 
*       describe: 插广告
*
************************************************************************
*/

#include "AdHelp.h"

AdHelp::AdHelp(){}
AdHelp::~AdHelp(){}

// -------------------------------------------------------------------------------------------------------------------------------------
// 无积分广告调用

/**
 * 展示插屏广告(C++ 通过JNI 调用JAVA方法)
 */
void AdHelp::showSpotAd()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    
    // 定义JNI函数信息结构体
    JniMethodInfo showSpotAd;
    
    /**
     * @param 第一个参数:JNI函数信息结构体
     * @param 第二个参数:与你Android项目中的主Activity所在的包名对应,Demo中为:com.youmi.android.cocos2dx.demo.MainActivity,需要改为com/youmi/android/cocos2dx/denmo/MainActivity
     * @param 第三个参数:Android项目中对应的Activity里面所定义的JAVA静态函数名,Demo中为:showSpotAd
     * @param 第四个参数:该JAVA方法所需要传入的值,格式为"(JAVA方法中需要传入的值)c++中本函数返回值",Demo中,showSpotAd的JAVA方法不需要传入值,而YoumiAd::showSpotAd()返回值为void,所以这里写 "()V" 
     * @return 返回bool值表示是否找到静态函数
     */
    bool isHave = JniHelper::getStaticmethodInfo(showSpotAd,"org/cocos2dx/cpp/AppActivity","showSpotAd","()V"); 
    if (!isHave) {
        cclog("jni:showSpotAd此函数不存在");
    }else{
        cclog("jni:showSpotAd函数存在");
        showSpotAd.env->CallStaticVoidMethod(showSpotAd.classID,showSpotAd.methodID);
    }
	#endif
}

/**
 * 关闭插屏广告(C++ 通过JNI 调用JAVA方法)
 */
bool AdHelp::closeSpotAd()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo closeSpotAd;
    bool isHave = JniHelper::getStaticmethodInfo(closeSpotAd,"closeSpotAd","()Z"); 
    if (!isHave) {
        cclog("jni:closeSpotAd此函数不存在");
        return false;
    }else{
        cclog("jni:closeSpotAd函数存在");
        return closeSpotAd.env->CallStaticBooleanMethod(closeSpotAd.classID,closeSpotAd.methodID);
    }
	#endif

	return true;
}


/**
 * 展示广告条(C++ 通过JNI 调用JAVA方法)
 */
void AdHelp::showBanner()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台

    // 定义JNI函数信息结构体
    JniMethodInfo showBanner;
    
    /**
     * @param 第一个参数:JNI函数信息结构体
     * @param 第二个参数:与你Android项目中的主Activity所在的包名对应,Demo中为:com.youmi.android.cocos2dx.demo.MainActivity,需要改为com/youmi/android/cocos2dx/denmo/MainActivity
     * @param 第三个参数:Android项目中对应的Activity里面所定义的JAVA静态函数名,Demo中为:showBanner
     * @param 第四个参数:该JAVA方法所需要传入的值,格式为"(JAVA方法中需要传入的值)c++中本函数返回值",Demo中,showBanner的JAVA方法不需要传入值,而YoumiAd::showBanner()返回值为void,所以这里写 "()V" 
     * @return 返回bool值表示是否找到静态函数
     */
    bool isHave = JniHelper::getStaticmethodInfo(showBanner,"showBanner","()V"); 
    if (!isHave) {
        cclog("jni:showBanner此函数不存在");
    }else{
        cclog("jni:showBanner函数存在");
        showBanner.env->CallStaticVoidMethod(showBanner.classID,showBanner.methodID);
    }
	#endif
}
 
/**
 * 隐藏广告条(C++ 通过JNI 调用JAVA方法)
 */
void AdHelp::hideBanner()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo hideBanner;
    bool isHave = JniHelper::getStaticmethodInfo(hideBanner,"hideBanner","()V"); 
    if (!isHave) {
        cclog("jni:hideBanner此函数不存在");
    }else{
        cclog("jni:hideBanner函数存在");
        hideBanner.env->CallStaticVoidMethod(hideBanner.classID,hideBanner.methodID);
    }
	#endif
}

// -------------------------------------------------------------------------------------------------------------------------------------
// 积分广告调用
/**
 * 展示积分墙(C++ 通过JNI 调用JAVA方法)
 */
void AdHelp::showOfferWall()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    
    // 定义JNI函数信息结构体
    JniMethodInfo showOfferWall;
    
    /**
     * @param 第一个参数:JNI函数信息结构体
     * @param 第二个参数:与你Android项目中的主Activity所在的包名对应,Demo中为:com.youmi.android.cocos2dx.demo.MainActivity,需要改为com/youmi/android/cocos2dx/denmo/MainActivity
     * @param 第三个参数:Android项目中对应的Activity里面所定义的JAVA静态函数名,Demo中为:showOfferWall
     * @param 第四个参数:该JAVA方法所需要传入的值,格式为"(JAVA方法中需要传入的值)c++中本函数返回值",Demo中,showOfferWall的JAVA方法不需要传入值,而YoumiAd::showOfferWall()返回值为void,所以这里写 "()V" 
     * @return 返回bool值表示是否找到静态函数
     */
    bool isHave = JniHelper::getStaticmethodInfo(showOfferWall,"showOfferWall","()V"); 
 
    if (!isHave) {
        cclog("jni:showOfferWall此函数不存在");
    }else{
        cclog("jni:showOfferWall函数存在");
        showOfferWall.env->CallStaticVoidMethod(showOfferWall.classID,showOfferWall.methodID);
    }
	#endif
}

/**
 * 展示积分墙对话框(C++ 通过JNI 调用JAVA方法)
 */
void AdHelp::showOfferWallDialog()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo showOfferWallDialog;
    bool isHave = JniHelper::getStaticmethodInfo(showOfferWallDialog,"showOfferWallDialog","()V"); 
 
    if (!isHave) {
        cclog("jni:showOfferWallDialog此函数不存在");
    }else{
        cclog("jni:showOfferWalDialogl函数存在");
        showOfferWallDialog.env->CallStaticVoidMethod(showOfferWallDialog.classID,showOfferWallDialog.methodID);
    }
	#endif
}

/**
 * 查询当前积分(C++ 通过JNI 调用JAVA方法)
 */
int AdHelp::queryPoints()
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo queryPoints;
    bool isHave = JniHelper::getStaticmethodInfo(queryPoints,"queryPoints","()I"); 
    if (!isHave) {
        cclog("jni:queryPoints此函数不存在");
        return -1;
    }else{
        cclog("jni:queryPoints函数存在");
		return queryPoints.env->CallStaticIntMethod(queryPoints.classID,queryPoints.methodID);
    }
	#endif

	return true;
}

/**
 * 奖励积分 (C++ 通过JNI 调用JAVA方法)
 */
bool AdHelp::awardPoints(int points)
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo awardPoints;
    bool isHave = JniHelper::getStaticmethodInfo(awardPoints,"awardPoints","(I)Z"); 
 
    if (!isHave) {
        cclog("jni:awardPoints此函数不存在");
        return false;
    }else{
        cclog("jni:awardPoints此函数存在");
        return awardPoints.env->CallStaticBooleanMethod(awardPoints.classID,awardPoints.methodID,points);
    }
	#endif

	return true;
}

/**
 * 消耗积分 (C++ 通过JNI 调用JAVA方法)
 */
bool AdHelp::spendPoints(int points)
{
	#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台
    JniMethodInfo spendPoints;
    bool isHave = JniHelper::getStaticmethodInfo(spendPoints,"spendPoints","(I)Z"); 
 
    if (!isHave) {
        cclog("jni:spendPoints此函数不存在");
        return false;
    }else{
        cclog("jni:spendPoints此函数存在");
        return spendPoints.env->CallStaticBooleanMethod(spendPoints.classID,spendPoints.methodID,points);
    }
	#endif

	return true;
}


好啦,完工!


之后在合适的位置调用AdHelp中相应的静态函数就行了。


最后不要忘了把新建的AdHelp.cpp和Classes目录下的其它类一样,也放在jni目录下的Android.mk 中。


重新编译运行,如果不出意外,就可以看到有米广告了。


Banner广告 插屏广告 积分墙



上线地址

91手机助手 百度助手

cocos2d-x 植入广告(二) 有米横屏、插屏广告和积分墙广告的更多相关文章

  1. ios – 当我在xCode 5中验证我的应用程序时,获取错误的广告标识符[IDFA]错误

    在验证我的应用程序时,我收到错误消息“广告标识符使用不当.您的应用包含广告标识符[IDFA]API,但您尚未遵守iOS中的限制广告跟踪设置.”我在广告标识符的准备上传页面上检查了“是”.我在我的应用程序中使用revmob广告和flurry分析(COCOS2D-X项目).如何解决这个问题,我已经尝试了很多但没有成功.我使用下面的代码进入appdelegate但没有运气.解决方法这个IDFA问题今天仍

  2. iOS上的自定义BLE广告

    有没有使用私有API或越狱的替代品?解决方法我对iOS的体验是,如果它没有在API中公开,除了越狱之外没有办法解决.对于蓝牙低功耗,API处于GAP/GATT级别,而较低级别暴露的则很少.广告是LL(链接层)功能.为了说明访问受限制的限制:扫描BLE设备时,您将无法访问广告商的MAC地址iOS.在Android中你有它.

  3. ios – 蓝牙LE,scanForPeripheralsWithServices在后台增加速度

    我在iPhone5S上使用蓝牙LE,我做了以下工作:>我有一个蓝牙外设,我配置它在所有三个蓝牙广告频道(37,38和39)上宣布每20秒.>我已经配置了我的应用程序与UIBacgroundModes=蓝牙中央在Info.plist>我已经启动了一个scanForperipheralsWithServices,如下所示码:目前的状态是:>在前台模式下,当我启动外围设备时(一秒钟内),应用程序会迅速收

  4. 2014年4月/ iOS 7 – 有没有办法跟踪iOS应用的转换,以便在不使用IDFA的情况下将内容下载到不同的广告系列来源?

    解决方法它现在似乎Apple特别允许使用IDFA跟踪安装.更新我的应用程序时,我看到:选择第二个选项没有出错,应用程序已获批准.

  5. 使用swift集成移动广告聚合平台

    OverridefuncviewDidLoad(){super.viewDidLoad()bannerView.adUnitId=“ca-app-pub-706657930853688714815911455”bannerView.rootViewController=selfself.view.addSubViewVarrequest:GADRequest=GADRequest()request.testDevices={“”}bannerView.loadRequest}Overridefuncdid

  6. 早期Swift中Cocos2D初始化代码的重构

    但是遗憾的是Swift2.2中还是不支持Type的class属性关键字,只能用static,我们期待Swift3的改进吧!

  7. 手把手教你swift项目添加cocos2dx-lua

    去倒杯水吧,这个过程会很久。。。至此,工程已经全部配置完毕,你已经解决一个大Boss了;今天就到这里吧,之后我们再续如何用swift调用lua手把手教你swift项目添加cocos2dx-lua

  8. 手把手教你swift项目集成cocos2dx-js模块

    前几天在swift项目中集成了Lua模块,使得在swift工程中用Lua写游戏逻辑成为了可能,具体工程及配置见手把手教你swift项目添加cocos2dx-lua,由于公司最近要把js做的小游戏集成到iOS原生应用中,于是我们将解锁另外一个场景,好了,下面开始;同样的,首先你得有一个swift项目我们从头开始,建立一个swift项目;我们默认你已经可以自己创建一个全新的swift项目了,这很简单,不是么?

  9. swift – 为什么我的facebook插页式广告不会显示在我的应用中?

    他们肯定也能在这里提供帮助.thispage之后的某个地方我相信你可以找到适当的现场支持作为付费广告客户.

  10. 设置Android隐私政策

    我在我的Android应用程序中使用AdMob.我是否需要在我的应用程序中创建隐私政策,以告知用户Google使用的Cookie?如果是,我需要把它放在哪里?我必须在GooglePlay上的说明中写出来吗?或者在第一次运行时我必须显示片段窗口吗?我阅读了Google文档,但我并不清楚.https://support.google.com/googleplay/android-developer/answer/2519872?hl=en解决方法澄清任何发现此问题的人:答案是肯定的,如果您使用的是AdMob,

随机推荐

  1. 【cocos2d-x 3.x 学习笔记】对象内存管理

    Cocos2d-x的内存管理cocos2d-x中使用的是上面的引用计数来管理内存,但是又增加了一些自己的特色。cocos2d-x中通过Ref类来实现引用计数,所有需要实现内存自动回收的类都应该继承自Ref类。下面是Ref类的定义:在cocos2d-x中创建对象通常有两种方式:这两中方式的差异可以参见我另一篇博文“对象创建方式讨论”。在cocos2d-x中提倡使用第二种方式,为了避免误用第一种方式,一般将构造函数设为protected或private。参考资料:[1]cocos2d-x高级开发教程2.3节[

  2. 利用cocos2dx 3.2开发消灭星星六如何在cocos2dx中显示中文

    由于编码的不同,在cocos2dx中的Label控件中如果放入中文字,往往会出现乱码。为了方便使用,我把这个从文档中获取中文字的方法放在一个头文件里面Chinese.h这里的tex_vec是cocos2dx提供的一个保存文档内容的一个容器。这里给出ChineseWords,xml的格式再看看ChineseWord的实现Chinese.cpp就这样,以后在需要用到中文字的地方,就先include这个头文件然后调用ChineseWord函数,获取一串中文字符串。

  3. 利用cocos2dx 3.2开发消灭星星七关于星星的算法

    在前面,我们已经在GameLayer中利用随机数初始化了一个StarMatrix,如果还不知道怎么创建星星矩阵请回去看看而且我们也讲了整个游戏的触摸事件的派发了。

  4. cocos2dx3.x 新手打包APK注意事项!

    这个在编译的时候就可以发现了比较好弄这只是我遇到的,其他的以后遇到再补充吧。。。以前被这两个问题坑了好久

  5. 利用cocos2dx 3.2开发消灭星星八游戏的结束判断与数据控制

    如果你看完之前的,那么你基本已经拥有一个消灭星星游戏的雏形。开始把剩下的两两互不相连的星星消去。那么如何判断是GameOver还是进入下一关呢。。其实游戏数据贯穿整个游戏,包括星星消除的时候要加到获得分数上,消去剩下两两不相连的星星的时候的加分政策等,因此如果前面没有做这一块的,最好回去搞一搞。

  6. 利用cocos2dx 3.2开发消灭星星九为游戏添加一些特效

    needClear是一个flag,当游戏判断不能再继续后,这个flag变为true,开始消除剩下的星星clearSumTime是一个累加器ONE_CLEAR_TIME就是每颗星星消除的时间2.连击加分信息一般消除一次星星都会有连击信息和加多少分的信息。其实这些combo标签就是一张图片,也是通过控制其属性或者runAction来实现。源码ComboEffect.hComboEffect.cpp4.消除星星粒子效果消除星星时,为了实现星星爆裂散落的效果,使用了cocos2d提供的粒子特效引擎对于粒子特效不了

  7. 02 Cocos2D-x引擎win7环境搭建及创建项目

    官网有搭建的文章,直接转载记录。环境搭建:本文介绍如何搭建Cocos2d-x3.2版本的开发环境。项目创建:一、通过命令创建项目前面搭建好环境后,怎样创建自己的Cocos2d-x项目呢?先来看看Cocos2d-x3.2的目录吧这就是Cocos2d-x3.2的目录。输入cocosnew项目名–p包名–lcpp–d路径回车就创建成功了例如:成功后,找到这个项目打开proj.win32目录下的Hello.slnF5成功了。

  8. 利用cocos2dx 3.2开发消灭星星十为游戏添加音效项目源码分享

    一个游戏,声音也是非常的重要,其实cocos2dx里面的简单音效引擎的使用是非常简单的。我这里只不过是用一个类对所有的音效进行管理罢了。Audio.hAudio.cpp好了,本系列教程到此结束,第一次写教程如有不对请见谅或指教,谢谢大家。最后附上整个项目的源代码点击打开链接

  9. 03 Helloworld

    程序都有一个入口点,在C++就是main函数了,打开main.cpp,代码如下:123456789101112131415161718#include"main.h"#include"AppDelegate.h"#include"cocos2d.h"USING_NS_CC;intAPIENTRY_tWinMain{UNREFERENCED_ParaMETER;UNREFERENCED_ParaMETER;//createtheapplicationinstanceAppDelegateapp;return

  10. MenuItemImage*图标菜单创建注意事项

    学习cocos2dx,看的是cocos2d-x3.x手游开发实例详解,这本书错误一大把,本着探索求知勇于发现错误改正错误的精神,我跟着书上的例子一起调试,当学习到场景切换这个小节的时候,出了个错误,卡了我好几个小时。

返回
顶部