2013-04-26 92 views
2

嗨我有一個使用android cocos2d開發的Android遊戲應用程序我需要整合admob我已經包括下面的代碼,但橫幅廣告不顯示請幫助這個你的答案將不勝感激,它會幫助很大。謝謝。Admob橫幅廣告不在Android中顯示

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> 

+0

並且您是否在清單中添加了必需的權限? – 2013-04-26 11:55:06

+0

你會發布整個代碼 – 2013-04-26 11:58:19

+0

多德發佈清單,並刪除admob ID – 2013-04-26 12:07:02

回答

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在我的情況下工作得很好。

+0

adMob可從android 3.2 – 2013-04-26 12:09:16

+0

獲得@Rstar:Yah,它也可以在'SDK'內的'extras'文件夾中找到,但它顯示了庫錯誤,它在我的情況下沒有工作,所以我添加了上述代碼的信息與Admob庫4.0.4版兼容。 – Harpreet 2013-04-26 12:19:24

+0

我想我認識你 – 2013-04-26 12:21:54

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); 
+0

'r.setTesting(true)'爲我工作 – 2013-10-28 10:59:20

+0

@Pratik Butan只是評論它。 – 2013-10-28 11:00:52

+0

現在還工作......爲什麼?當我上傳我的apk然後它必須我評論,對吧? – 2013-10-28 12:50:09

0

確保你正確包括ID,並有對應的權限爲您的應用程序。

另外,實施ADListener可以很好地展示ADListener如何實現廣告呈現。

另外不要忘記設置測試模式來查詢廣告,AdMob傢伙可以禁止你的不負責任的點擊。

0

在Android的最新廣告

使用下面的代碼

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

怎麼一回事,因爲在AdRequest類final類,所以我們不能創建對象。