码迷,mamicode.com
首页 > 移动开发 > 详细

Yomob广告在cocos2dx安卓平台的Demo

时间:2017-05-07 19:49:24      阅读:468      评论:0      收藏:0      [点我收藏+]

标签:config   resume   iad   文件的   环境   配置环境   ges   ant   win   

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

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

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

技术分享

 

添加如下代码到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");

    }

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

技术分享

 

技术分享

 

 

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

项目正在上传,请稍后!

 

Yomob广告在cocos2dx安卓平台的Demo

标签:config   resume   iad   文件的   环境   配置环境   ges   ant   win   

原文地址:http://www.cnblogs.com/txfd/p/6821170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!