Yomob广告在cocos2dx安卓平台的Demo

时间:2022-09-21 07:38:41

Yomob 也是一个广告平台:他的使用方式比较简单哈,这里只说说他的步骤

按照官方文档说明配置环境,我使用的是eclipse,在eclipse上自己将文件copy到项目proj.android下,覆盖掉源目录

将项目下的libs目录下的所有的jar文件,选中右键build Path

Yomob广告在cocos2dx安卓平台的Demo

添加如下代码到Manifest.xml文件的<application>标签下:

        <!-- Inmobi -->
<activity
android:name="com.inmobi.rendering.InMobiAdActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:hardwareAccelerated="true" />
<receiver
android:name="com.inmobi.commons.core.utilities.uid.ImIdShareBroadCastReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.inmobi.share.id" />
</intent-filter>
</receiver> <!-- TG CP -->
<activity android:name="com.soulgame.sgsdk.adsdk.TGCPADActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> <!-- DianJoy -->
<service
android:name="com.dianjoy.video.DianViewService"
android:process=":playgame" />
<activity
android:name="com.dianjoy.video.DianViewActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"/>
<activity
android:name="com.dianjoy.video.DianViewAdBrowser"
android:configChanges="orientation|screenSize"/> <!-- AYang -->
<activity
android:name="com.afk.client.ads.AdActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" /> <activity
android:name="com.afk.permission.RequestPermissionActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> <service
android:name="com.afk.client.ads.DownloadService"
android:exported="false" /> <!-- Vungle -->
<activity
android:name="com.vungle.publisher.VideoFullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
<activity android:name="com.vungle.publisher.MraidFullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/> <!-- Domob -->
<activity
android:name="com.pad.android_independent_video_sdk.view.DvxVideoActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|screenSize|screenLayout"/>
<service android:name="com.pad.android_independent_video_sdk.IndependentService"/>

需要说明的是以上是国内安卓的sdk;其他的sdk请按照官方的文档配置。

直接添加权限到Manifest.xml下的<manifest.xml>的标签下:

    <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />

添加官方给的TGSDKCocos2dxHelper.h和TGSDKCocos2dxHelper.cpp到Classes文件下,记得要在Android.mk文件里面添加他的路径

然后就可以直接在cocos2dx的C++代码里面调用使用了,还有一点需要使用说明的,AppActivity.java 里面需要加入以下代码,否则会报Activity为null。

/****************************************************************************
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 java.util.Map; import org.cocos2dx.lib.Cocos2dxActivity; import com.soulgame.sgsdk.tgsdklib.TGSDK;
import com.soulgame.sgsdk.tgsdklib.TGSDKServiceResultCallBack;
import com.soulgame.sgsdk.tgsdklib.ad.ITGADListener;
import com.soulgame.sgsdk.tgsdklib.ad.ITGPreloadListener;
import com.soulgame.sgsdk.tgsdklib.ad.ITGRewardVideoADListener;
import com.soulgame.sgsdk.tgsdklib.cocos2dx.TGSDKCocos2dxHelper; import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.view.ViewGroup.LayoutParams; public class AppActivity extends Cocos2dxActivity { private static AppActivity _appActiviy; @Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//横屏:根据传感器横向切换
TGSDK.setDebugModel(true);
TGSDKCocos2dxHelper.setup(this);
} @Override
protected void onStart() {
super.onStart();
TGSDK.onStart(this);
} @Override
protected void onStop() {
super.onStop();
TGSDK.onStop(this);
} @Override
protected void onPause() {
super.onPause();
TGSDK.onPause(this);
} @Override
protected void onResume() {
super.onResume();
TGSDK.onResume(this);
} @Override
protected void onDestroy() {
super.onDestroy();
TGSDK.onDestroy(this);
} @Override
protected void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
TGSDK.onActivityResult(this, reqCode, resCode, data);
} }

Yomob的调用代码很简单:

    yomob::TGSDKCocos2dxHelper::setDebugModel(true);
yomob::TGSDKCocos2dxHelper::initialize("p196wHvufx005lPj2P63");//参数需要自己申请生成,需要特定的包名才能正常显示广告哦,而且他们的资源有时候没有广告,所以要注意下方log信息。
yomob::TGSDKCocos2dxHelper::preload(); if (yomob::TGSDKCocos2dxHelper::couldShowAd("vVxf8P1riB0IVfalxPy")) {
yomob::TGSDKCocos2dxHelper::showAd("vVxf8P1riB0IVfalxPy"); }

这几行代码官方都有说明,在你需要调用的地方调用即可。

Yomob广告在cocos2dx安卓平台的Demo

Yomob广告在cocos2dx安卓平台的Demo

以下给出GitHub Demo·的源代码地址:https://github.com/DiaoYung/YomobDemo;诸位可以在github上下载源码实践。然后运用到自己的项目中。

项目正在上传,请稍后!

Yomob广告在cocos2dx安卓平台的Demo的更多相关文章

  1. cocos2d-x 3&period;0 WIN7&plus;VS2012 安卓平台搭建

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  2. cocos2d-x hello world及安卓平台迁移

        本节和大家一起新建一个项目工程,并通过cygwin迁移至android平台.      以下是本节主要内容: 利用cocos2d-x自带脚本,生成测试工程,并测试运行: 将该测试项目通过cyg ...

  3. 安卓平台 全面支持软解和硬解的SDK-Demo源代码开放

    专业做视频编解码的SDK开发工作. 2015年12月1日10:46:55: 更新到1.5.0版本 功能列表: 基本播放: 1,正常播放, 支持MP4,FLV,AVI,TS,3GP,RMVB,WM,WM ...

  4. 迅雷云加速开放平台c&num;demo

    迅雷云加速开放平台c#demo.很多人很遇到下载文件的问题.这个例子是调用迅雷云加速开放平台的dll,进行下载,速度很快,下载过程中可以获取到很全的下载信息,比如下载速度,进度,完成状态等. 例子中带 ...

  5. 在Unity3D中实现安卓平台的本地通知推送

    [前言] 对于手游来说,什么时候需要推送呢?玩过一些带体力限制的游戏就会发现,我的体力在恢复满后,手机会收到一个通知告诉我体力已完全恢复了.这类通知通常是由本地的客户端发起的,没有经过服务端. 在安卓 ...

  6. ionic3 打包安卓平台环境搭建报错解决方案总结

    1.jvm虚拟机提供的运行空间小于项目所需的空间是报错.如图: 解决方法:在环境变量中配置jvm的运行内存大小,大于所需的内存即可. 其中:-Xmx512M可根据实际提示情况,进行更改,如1024M, ...

  7. Unity切换到安卓平台Shader丢失&lpar;opengl&rpar;

    Unity安卓平台shader平台丢失 Unity的工程切换到Android平台后,运行游戏出现shader丢失 解决办法:在Unity桌面图标的快捷方式后添加 -force-gles20 示例:&q ...

  8. 接入Gobelieve IM开发平台的DEMO代码

    接入Gobelieve IM开发平台的DEMO代码, 请求头部: Authorization: Basic $base64(appid:$hex_md5(appsecret))意思是 appsecre ...

  9. 安卓平台ARM Mali OpenCL例子-灰度转换(转)

    手头一块RK3288的板子,在板子上测试了一张1080p的彩色图灰度转换的OpenCL例子.OpenCL没有任何优化.例子请移步这里. 该例子是编译成安卓平台下的可执行程序. 进入jni文件夹,进行如 ...

随机推荐

  1. Apache Shiro 学习记录3

    晚上看了教程的第三章....感觉Shiro字符串权限很好用....但是教程举的例子太少了.....而且有些地方讲的不是很清楚....所以我也自己测试了一下....记录一下测试的结果.... (1) * ...

  2. 2013 duilib入门简明教程 -- 其他 &lpar;18&rpar;

    一.超链接按钮      代码很简单,参见360Demo:      <Button text="{u}{a}求助{/a}{/u}" showhtml="true& ...

  3. bzoj 3172 单词 ac自动机&vert;后缀数组

    题目大意: 给定n个字符串连成了一篇文章,问每个字符串在这篇文章中出现的次数,可重复覆盖 这里ac自动机和后缀数组都可以做 当然后缀数组很容易就解决,但是相对时间消耗高 这里就只讲ac自动机了 将每个 ...

  4. jekins 持续集成手记

    1.安装一个干净Ubuntu14.04桌面版本 2.打开http://jenkins-ci.org/ 官网, 选择use jenkins 中, Installing Jenkins on Ubuntu ...

  5. Hadoop环境常用命令

    用户可以通过dfsadmin -safemode value   来操作安全模式,参数value的说明如下: enter - 进入安全模式 leave - 强制NameNode离开安全模式 get - ...

  6. sql查询比较两表不同数据与相同数据

    以下举例是查询相同数据,否则则相反 方法一: select * from A as x,B as y where x.a1=y.b1 and x.a2=y.b2 and x.a3=y.b3 方法二: ...

  7. 在 WinForm 中打开页面采用POST方式传参http。可以多个参数传递,返回json字符串

    //调用方法 Dictionary<string, string> postData = new Dictionary<string, string>(); postData. ...

  8. 基于Bootstrap的Asp&period;net Mvc 分页

    基于Bootstrap的Asp.net Mvc 分页的实现 最近写了一个mvc 的 分页,样式是基于 bootstrap 的 ,提供查询条件,不过可以自己写样式根据个人的喜好,以此分享一下.首先新建一 ...

  9. ubuntu libtiff-dev

    cc@cc:~$ dpkg -L libti libtiff5 libtiffxx5 libtimezonemap1 libtinyxml2- libtiff5-dev libtimedate-per ...

  10. BZOJ2002&lbrack;Hnoi2010&rsqb;弹飞绵羊——LCT

    题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...