gpt4 book ai didi

android - Admob 横幅广告未在 Android 中显示

转载 作者:行者123 更新时间:2023-11-29 00:30:09 29 4
gpt4 key购买 nike

您好,我有一个使用 android cocos2d 开发的 Android 游戏应用程序,我需要集成 admob 我已经包含了以下代码,但横幅广告没有显示,请就此提供帮助,我们将不胜感激您的回答,这将是一个很大的帮助。谢谢。

public class MainActivity extends Activity {
private CCGLSurfaceView mGLSurfaceView;
private boolean isCreated = false;
public static FrameLayout m_rootLayout;
AdView adView;

// This is used to display Toast messages and is not necessary for your app
@Override
protected void onCreate(Bundle savedInstanceState) {
if (!isCreated) {
isCreated = true;
} else {
return;
}

super.onCreate(savedInstanceState);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

try{
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);

adView = new AdView(this, AdSize.BANNER, "admob id");

AdRequest request = new AdRequest();
adView.loadAd(request);
// Adding full screen container
addContentView(adView, adParams);
}catch (Exception e) {
FlurryAgent.logEvent("ADMOB ERROR: "+e);
}



mGLSurfaceView = new CCGLSurfaceView(this);
setContentView(mGLSurfaceView);


CCDirector.sharedDirector().attachInView(mGLSurfaceView);

getScaledCoordinate();

Global.assetManager = getAssets();
Global.context = this;
Global.loadUserInfo();
CCScene scene = CCScene.node();
scene.addChild(new SplashScene(), -1);

CCDirector.sharedDirector().runWithScene(scene);


//-------------IAP-----------------------
Log.d(TAG1, "Creating IAB helper.");
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
Log.d(TAG1, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");

if (!result.isSuccess()) {
// Oh noes, there was a problem.
complain("Problem setting up in-app billing: " + result);
return;
}

// Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
Log.d(TAG, "Setup successful. Querying inventory.");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});


Global.myActivity=this;
}

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.puzzlegame"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.game.puzzlegame.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.revmob.ads.fullscreen.FullscreenActivity"
android:configChanges="keyboardHidden|orientation" >
</activity>

<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"></activity>
</application>

最佳答案

请检查您项目中的所有这些新增内容。

在 Java 类中:

AdView layout = (AdView)this.findViewById(R.id.adView); 
AdRequest adRequest = new AdRequest();
//adRequest.setTesting(true);
layout.loadAd(adRequest);

在布局中:

<LinearLayout        
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads">

<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="your key" />
</LinearLayout>

在 list 中:

<activity android:name="com.google.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation" />

我曾使用过 AdMob Lib。版本。 4.0.4 在我的案例中运行良好。

关于android - Admob 横幅广告未在 Android 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16235779/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com