我想放置廣告在下面的FrameLayout我MainActivity這樣的:AdMob的旗幟問題的android
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
xmlns:ads="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:id="@+id/fragmentContainer"
android:layout_centerHorizontal="true">
</FrameLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
我已經加入這個我清單: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
而且我的構建.gradle也很好看。這是我的Java代碼:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(),"ca-app-pub-xxxxxxxx~xxx");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // An example device ID
.build();
mAdView.loadAd(request);
但是當我運行應用程序,我看不到廣告,然後在logcat中我得到這個錯誤:
W/Ads: Invalid unknown request error: [Cannot determine request type. Is your ad unit id correct?]
W/Ads: There was a problem getting an ad response. ErrorCode: 1
W/Ads: Failed to load ad: 1
我已經嘗試了幾乎所有我在網上找到的東西,但沒有爲我工作。我認爲可能問題出在我的activity_main.xml中,因爲FrameLayout沒有給予廣告足夠的位置。