2013-11-26 73 views
2

我tryed所有代碼來自世界各地和我有兩件事情:1)錯誤或2)鴕鳥政策看到廣告..如何查看我的AdMob廣告?

這是我的清單:

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

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.adview.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.google.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 
    </application> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
</manifest> 

已更新!!!! **這是我佈局:**

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"  
android:id="@+id/layout" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="@string/hello_world" /> 

<com.google.ads.AdView android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    ads:adUnitId="xxxxxxxx" i put my editor id here.. 
    ads:loadAdOnCreate="true" 
    ads:adSize="BANNER"/> 

</RelativeLayout> 

而且...... 這是我類(我不把任何東西,因爲我在佈局做到了)

package com.example.adview; 



import android.os.Bundle; 
import com.google.ads.AdRequest; 
import com.google.ads.AdSize; 
import com.google.ads.AdView; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.LinearLayout; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 



} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

} 

我把GoogleAdMobAdsSdk-6.4.1(最新版本)放在libs中,然後在Project> RightClick> Properties> JavaBuildPath> AddExternalJARs> GoogleAdMobAdsSdk-6.4.1

回答

0
在你比如

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

加入這個

xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 

layout.xml主要活動

,你必須tihs行添加到您的廣告代碼

ads:loadAdOnCreate="true"

+0

好,但鴕鳥政策工作d: 我的佈局是這樣的: <的RelativeLayout的xmlns:安卓= 「http://schemas.android.com/apk/res/android」 xmlns:tools =「http://schemas.android.com/tools」 xmlns:ads =「http://schemas.android.com/apk/lib/com.google.ads」 android:orientation =「垂直「 android:layout_width =」fill_parent「 android:layout_height =」fill_parent「 android:id =」@ + id/layout「 android:paddingBottom =」@dimen/activit y_vertical_margin 「 的android:paddingLeft = 」@捫/ activity_horizo​​ntal_margin「 我把這麼多的評論,因爲我不能把完整的代碼d: –

+0

的android:paddingRight = 」@捫/ activity_horizo​​ntal_margin「 機器人:paddingTop =」 @捫/ activity_vertical_margin 「 工具:上下文=」 MainActivity 「>

+0

@JackķFouani –

0

您需要將此添加到您的AdView

ads:loadAdOnCreate="true" 

或者您需要以編程方式從您的活動(我建議在onCreate)加載您的添加。

final AdView adView = findViewById(R.id.adView); 
adView.load(new AdRequest()); 
0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/ad_layout" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal"> 
    </LinearLayout> 

    ... Other View 

</LinearLayout> 

LinearLayout ad_layout = (LinearLayout) findViewById(R.id.ad_layout); 
ad_layout.setOrientation(LinearLayout.VERTICAL); 

mAdView = new AdView(this); 
mAdView.setAdSize(AdSize.BANNER); 
mAdView.setAdUnitId(UNIT_ID); 

AdRequest.Builder adRequest = new AdRequest.Builder(); 
adRequest.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); 
adRequest.addTestDevice("3204995868e01153"); 
adRequest.addTestDevice("b9ceca537aaddee2"); 

ad_layout.addView(mAdView); 

mAdView.loadAd(adRequest.build());