Admob横幅广告未在Android中显示

时间:2013-04-26 11:52:36

标签: android admob

您好我有一个使用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 个答案:

答案 0 :(得分: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>

In Manifest:

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

我曾与 AdMob Lib合作过。版本。 4.0.4 在我的案例中运作良好。

答案 1 :(得分: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);

答案 2 :(得分:0)

确保您包含正确的ID并具有相应的应用权限。

此外,最好实现真正展示其广告呈现方式的ADListener。

另外,不要忘记将测试模式设置为查询广告,AdMob的玩家可以禁止您进行不负责任的点击。

答案 3 :(得分:0)

适用于Android的最新广告

使用下面的代码

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

因为AdRequest类的最终类因此我们无法创建对象。