Cocos2d-x3.3RC0实现有米广告平台接入
有米广告平台介绍:有米SDK 关于有米的一些信息设置,官网表述的已经非常清楚,此处不再赘述,本教程是针对Android机器。 直接上代码 1】C部分 本教程基于Cocos2d-x的HelloWorld空程序,所以代码非常简单,不需修改C部分代码 2】Java代码 1、AppActivity.jav
有米广告平台介绍:有米SDK
关于有米的一些信息设置,官网表述的已经非常清楚,此处不再赘述,本教程是针对Android机器。
直接上代码
1】C++部分
本教程基于Cocos2d-x的HelloWorld空程序,所以代码非常简单,不需修改C++部分代码
2】Java代码
1、AppActivity.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.spot.SpotDialogListener; import net.youmi.android.spot.SpotManager; import org.cocos2dx.lib.Cocos2dxActivity; import org.cocos2dx.lib.Cocos2dxEditText; import org.cocos2dx.lib.Cocos2dxGLSurfaceView; import org.cocos2dx.lib.Cocos2dxRenderer; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; import com.yxk.youmi.R; public class AppActivity extends Cocos2dxActivity { // SpotManager.getInstance(sActivity).showSpotAds(sActivity); private Cocos2dxGLSurfaceView mGLView;//add private static Context mContext;//add protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; //add LayoutParams frameLayout_paras = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); FrameLayout frameLayout = new FrameLayout(this); frameLayout.setLayoutParams(frameLayout_paras); ViewGroup.LayoutParams edittext_layout_params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); Cocos2dxEditText editText = new Cocos2dxEditText(this); editText.setLayoutParams(edittext_layout_params); frameLayout.addView(editText); mGLView = new Cocos2dxGLSurfaceView(this); frameLayout.addView(mGLView); mGLView.setEGLContextClientVersion(2); mGLView.setCocos2dxRenderer(new Cocos2dxRenderer()); setContentView(frameLayout); LinearLayout adMiniLayout = new LinearLayout(this); adMiniLayout.setOrientation(LinearLayout.VERTICAL); FrameLayout.LayoutParams lp_mini = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); //设置adMiniLayout的悬浮位置,具体的位置开发者根据需要设置 lp_mini.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;//这里确定广告的位置 this.addContentView(adMiniLayout, lp_mini); LinearLayout miniLayout = new LinearLayout(this); miniLayout.setGravity(Gravity.CENTER_HORIZONTAL); adMiniLayout.addView(miniLayout); AdManager.getInstance(this).init("937f81391fe278d0", "11f447b520039ceb", false); AdView adView = new AdView(this, AdSize.FIT_SCREEN); miniLayout.addView(adView); // 监听广告条接口 adView.setAdListener(new AdViewListener() { @Override public void onSwitchedAd(AdView arg0) { Log.i("YoumiAdDemo", "广告条切换"); } @Override public void onReceivedAd(AdView arg0) { Log.i("YoumiAdDemo", "请求广告成功"); } @Override public void onFailedToReceivedAd(AdView arg0) { Log.i("YoumiAdDemo", "请求广告失败"); } }); SpotManager.getInstance(this).loadSpotAds(); SpotManager.getInstance(this).setShowInterval(20);// 设置20秒的显示时间间隔 SpotManager.getInstance(this).setSpotOrientation( SpotManager.ORIENTATION_PORTRAIT); } /* Button spotBtn = (Button) findViewById(R.id.showSpot); spotBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 展示插播广告,可以不调用loadSpot独立使用 SpotManager.getInstance(AppActivity.this).showSpotAds( AppActivity.this, new SpotDialogListener() { @Override public void onShowSuccess() { Log.i("YoumiAdDemo", "展示成功"); } @Override public void onShowFailed() { Log.i("YoumiAdDemo", "展示失败"); } @Override public void onSpotClosed() { Log.e("YoumiAdDemo", "插屏关闭"); } }); // // // 可以根据需要设置Theme,如下调用,如果无特殊需求,直接调用上方的接口即可 // SpotManager.getInstance(YoumiAdDemo.this).showSpotAds(YoumiAdDemo.this, // android.R.style.Theme_Translucent_NoTitleBar); // // } }); Button diyBtn = (Button) findViewById(R.id.diy); diyBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setClass(AppActivity.this, DiyDemo.class); startActivity(intent); } }); } */ // setContentView(R.layout.main);//del /* AdManager.getInstance(this).init("937f81391fe278d0", "11f447b520039ceb", false); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); // 设置广告条的悬浮位置 layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; // 这里示例为右下角 // 实例化广告条 AdView adView = new AdView(this, AdSize.FIT_SCREEN); // 调用Activity的addContentView函数 this.addContentView(adView, layoutParams); // 监听广告条接口 adView.setAdListener(new AdViewListener() { @Override public void onSwitchedAd(AdView arg0) { Log.i("YoumiAdDemo", "广告条切换"); } @Override public void onReceivedAd(AdView arg0) { Log.i("YoumiAdDemo", "请求广告成功"); } @Override public void onFailedToReceivedAd(AdView arg0) { Log.i("YoumiAdDemo", "请求广告失败"); } }); SpotManager.getInstance(this).loadSpotAds(); SpotManager.getInstance(this).setShowInterval(20);// 设置20秒的显示时间间隔 SpotManager.getInstance(this).setSpotOrientation( SpotManager.ORIENTATION_PORTRAIT); Button spotBtn = (Button) findViewById(R.id.showSpot); spotBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 展示插播广告,可以不调用loadSpot独立使用 SpotManager.getInstance(AppActivity.this).showSpotAds( AppActivity.this, new SpotDialogListener() { @Override public void onShowSuccess() { Log.i("YoumiAdDemo", "展示成功"); } @Override public void onShowFailed() { Log.i("YoumiAdDemo", "展示失败"); } @Override public void onSpotClosed() { Log.e("YoumiAdDemo", "插屏关闭"); } }); // // // 可以根据需要设置Theme,如下调用,如果无特殊需求,直接调用上方的接口即可 // SpotManager.getInstance(YoumiAdDemo.this).showSpotAds(YoumiAdDemo.this, // android.R.style.Theme_Translucent_NoTitleBar); // // } }); Button diyBtn = (Button) findViewById(R.id.diy); diyBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setClass(AppActivity.this, DiyDemo.class); startActivity(intent); } }); } */ @Override public void onBackPressed() { // 如果有需要,可以点击后退关闭插播广告。 if (!SpotManager.getInstance(AppActivity.this).disMiss(true)) { super.onBackPressed(); } } @Override protected void onStop() { // 如果不调用此方法,则按home键的时候会出现图标无法显示的情况。 SpotManager.getInstance(AppActivity.this).disMiss(false); super.onStop(); } @Override protected void onDestroy() { SpotManager.getInstance(this).unregisterSceenReceiver(); super.onDestroy(); } }
2、DiyDemo.java
package org.cocos2dx.cpp; import java.util.List; import com.yxk.youmi.R; import net.youmi.android.diy.AdObject; import net.youmi.android.diy.DiyManager; import net.youmi.android.diy.banner.DiyAdSize; import net.youmi.android.diy.banner.DiyBanner; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; public class DiyDemo extends Activity{ private Button showRecommendWallBtn, showRecommendAppWallBtn, showRecommendGameWallBtn; private List<adobject> adList; public void onCreate(Bundle bundle){ super.onCreate(bundle); setContentView(R.layout.activity_diydemo); //普通布局,适用于应用 //获取要嵌入迷你广告条的布局 RelativeLayout adLayout=(RelativeLayout)findViewById(R.id.adLayout); //demo 1 迷你Banner : 宽满屏,高32dp DiyBanner banner = new DiyBanner(this, DiyAdSize.SIZE_MATCH_SCREENx32);//传入高度为32dp的AdSize来定义迷你Banner //demo 2 迷你Banner : 宽320dp,高32dp //DiyBanner banner = new DiyBanner(this, DiyAdSize.SIZE_320x32);//传入高度为32dp的AdSize来定义迷你Banner //将积分Banner加入到布局中 adLayout.addView(banner); //悬浮布局,适用于游戏 /* //实例化LayoutParams(重要) FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); //设置迷你Banner的悬浮位置 layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; // 这里示例为右下角 //实例化迷你Banner DiyBanner banner = new DiyBanner(this, DiyAdSize.SIZE_MATCH_SCREENx32);//传入高度为32dp的DiyAdSize来定义迷你Banner //调用Activity的addContentView函数 this.addContentView(banner, layoutParams); */ showRecommendWallBtn = (Button) findViewById(R.id.showRecommendWall); showRecommendWallBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 展示所有应用推荐墙 DiyManager.showRecommendWall(DiyDemo.this); } }); showRecommendAppWallBtn = (Button) findViewById(R.id.showRecommendAppWall); showRecommendAppWallBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 展示应用推荐墙 DiyManager.showRecommendAppWall(DiyDemo.this); } }); showRecommendGameWallBtn = (Button) findViewById(R.id.showRecommendGameWall); showRecommendGameWallBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 展示游戏推荐墙 DiyManager.showRecommendGameWall(DiyDemo.this); } }); } }</adobject>
3、AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yxk.youmi" android:versioncode="1" android:versionname="1.0" android:installlocation="auto"> <uses-sdk android:minsdkversion="11"></uses-sdk> <uses-feature android:glesversion="0x00020000"></uses-feature> <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"></meta-data> <activity android:name="org.cocos2dx.cpp.AppActivity" android:label="@string/app_name" android:screenorientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configchanges="keyboard|keyboardHidden|orientation|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN"></action> <category android:name="android.intent.category.LAUNCHER"></category> </intent-filter> </activity> <activity android:name="net.youmi.android.AdBrowser" android:configchanges="keyboard|keyboardHidden|orientation|screenSize" 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"></action> <data android:scheme="package"></data> </intent-filter> </receiver> <provider android:name="net.youmi.android.spot.SpotAdContentProvider" android:authorities="com.youandroidmi"></provider> <activity android:name="org.cocos2dx.cpp.DiyDemo" android:configchanges="keyboard|keyboardHidden|navigation|orientation|screenSize"> </activity> <meta-data android:name="YOUMI_CHANNEL" android:value="0"> </meta-data> </application> <supports-screens android:anydensity="true" android:smallscreens="true" android:normalscreens="true" android:largescreens="true" android:xlargescreens="true"></supports-screens> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission> <uses-permission android:name="android.permission.GET_TASKS"></uses-permission> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> </manifest>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to turn off the ads recommended by 360 Browser? I believe that many users are using 360 Browser, but this browser sometimes pops up advertisements, which makes many users very distressed. Let this site carefully introduce to users how to Turn off the ads recommended by 360 Browser on your computer. How to turn off the ads recommended by 360 Browser on your computer? Method 1: 1. Open 360 Safe Browser. 2. Find the "three horizontal bars" logo in the upper right corner and click [Settings]. 3. Find [Lab] in the taskbar on the left side of the pop-up interface, and check [Enable "360 Hotspot Information" function]. Method 2: 1. First double-click

Users will encounter a lot of advertisements when browsing Moments, so how can they completely turn off the advertisements? Users need to click Settings in My, then find Personal Information and Permissions, then click Personalized Ads Management, and just turn off ad personalization. This article will tell you how to completely turn off ads in Moments, so take a look! WeChat usage tutorial: How to completely turn off ads in Moments? Answer: It cannot be turned off completely. You can only turn off personalized recommendations. Specific methods: 1. First, click on me, and then find the settings inside. 2. Find the personal information and permissions options. 3. Click on the personalized advertising management function inside. 4. Click the switch on the right side of ad personalization and turn it off. How to turn off ads: 1. Find the ads in Moments. 2. Click right

With the advancement of communication technology, telephone contact has become more and more common in our daily lives. However, sometimes we may try to call a number only to find that the number is no longer reachable. In order to save time and energy, many people start looking for empty number verification services to confirm the validity of the number. This service can help users quickly check whether a number is valid and avoid unnecessary trouble. 1. What are the empty account detection platforms? Users can check the status of the number, including whether it is empty, by dialing the corresponding inquiry number or visiting the official website through the official inquiry service provided by the operator. This service is provided by many operators to facilitate users to quickly understand the usage of the number. Online empty number detection platforms are now emerging in an endless stream on the market. These platforms provide quick and convenient

After updating the Edge browser, many users found that there were a lot of advertisements on the interface. For example, at the bottom of the new tab page, there were links to multiple websites and the word advertisements were marked, which looked very annoying. Is there any way to turn off personalized ads in Edge browser? The editor has searched many methods on the Internet, and I will share with you a little trick to turn off ads. How to turn off ads in the new version of Edge? 1. Open the Edge browser. 2. Click [•••] in the upper right corner. 3. Click [Settings]. 4. Click [Privacy, Search and Services]. 5. Turn off the switch on the right side of "Personalize your web experience" to turn off the personalization pushed by Microsoft.

Where can I buy Optimism coins? Optimism Coin can be purchased on a number of cryptocurrency exchanges, including: Binance Huobi OKX Matcha Gate.io Kraken Bittrex Poloniex Coinbase Pro Gemini You will need to register an account with these exchanges and complete identity verification before you can purchase Optimism Coin. The steps to purchase Optimism coins are as follows: Choose a safe and reliable exchange. Register an account and complete identity verification. Fund your account. On the trading interface of the trading platform, find the trading pair of Optimism currency, such as OP/USDT. Enter the amount of Optimism coins you want to purchase and click

When we usually use Douyin for entertainment, we often have some inexplicable and strange advertisements that disturb our leisure experience. Many users are not disturbed by them and want to turn off the recommendation push of these advertisements, but they don't. If you know how to operate it, then the editor of this website will bring you this tutorial guide and this detailed introduction, hoping to help everyone in need. First, we first find the option to understand and manage ad push in the app settings, then see all the ad-related switch options below, click the switch at the back to turn it off, and then a confirmation prompt to turn off the ad will pop up, we click to confirm. Close ads

Where can I buy EC coins? On which platform are EC coins traded? Text: EC coin (Ethereum Classic, abbreviation: ETC) is an open source, decentralized blockchain platform and the first hard fork currency of Ethereum. EC Coin has a similar technical foundation to Ethereum, but there are also some key differences. For example, EC Coin has a shorter block time and does not use the Proof of Stake (PoS) consensus mechanism. EC coins can be purchased on many cryptocurrency trading platforms, including: Centralized exchanges: Binance, Huobi, OKX, Matcha, Gate.io, Kraken, Bittrex, Poloniex, etc. Decentralized exchanges: PancakeSwap, Uniswap, Su

Kuaishou Express Edition has always been so popular with everyone. It can view a large number of videos every day. It is constantly updated, so that everyone can see these wonderful video contents anytime, anywhere. It is really rich, diverse and direct. To relieve worries and boredom, sometimes everyone always encounters some advertising pop-ups, which directly affects everyone's perception of watching videos, so everyone wants to close these advertising pop-ups to obtain a more comfortable viewing experience. Friends who don’t know how to operate it can take a look at the tutorial I brought to you. How to turn off advertising push in Kuaishou Express Edition: 1. First open the Kuaishou Express Edition software, go to the Kuaishou page and click the [three horizontal lines] icon in the upper left corner; 2. Then click [Settings] on the current page; 3. Enter
