3

嗨,我有一个使用 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;
}

显现

<?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>

4

4 回答 4

1

试试这个代码

LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
        getWindowManager().getDefaultDisplay().getWidth(),
        getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
AdView ad = new AdView(this, AdSize.BANNER, "admob_id");
adParams.addView(ad);
AdRequest r = new AdRequest();
//r.setTesting(true);
ad.loadAd(r);
于 2013-04-26T12:15:13.793 回答
1

请查看您项目中的所有这些添加。

在 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>

在清单中:

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

我曾与AdMob Lib 合作过。版本。4.0.4在我的情况下效果很好。

于 2013-04-26T12:07:03.450 回答
0

确保您提供了正确的 ID 并为您的应用程序提供了相应的权限。

此外,最好实现 ADListener,它可以真正显示其与广告渲染的关系。

也不要忘记设置测试模式来查询广告,AdMob 家伙可以禁止你不负责任的点击。

于 2013-04-26T12:16:43.783 回答
0

用于 Android 中的最新广告

使用下面的代码

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

因为 AdRequest 类是最终类,所以我们无法创建对象。

于 2016-07-15T09:53:10.913 回答