0
我按照這個教程:AdMob Code無法獲得AdMobs到地圖顯示了
但我不能讓旗幟,以顯示(甚至沒有,我已經看到網上有很多共同的XML adSize時錯誤:
這是我main_activity代碼:
private AdView adView;
private static final String AD_UNIT_ID = "ca-app-pub-XXXXXXXXXXXXXXXXXX";
GoogleMap mMap;
LatLng myposition;
Marker marker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
//Add the AdView to the view hierarchy.The view will have no size
//Until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.lyout);
layout.addView(adView);
//Create an ad request. Check kogcat output for the hashed device ID to
//get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("MY_DEVICE_ID")
.build();
//Start loading the ad in the background.
adView.loadAd(adRequest);
}
這是我的佈局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/lyout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTilt="45"
map:cameraZoom="15"
/>
</LinearLayout>
起初,我的佈局文件只有:
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTilt="45"
map:cameraZoom="15"
/>
編輯:logcat的去除工作
但是,這並沒有任何工作。我如何獲得這些廣告展示?
感謝
Rushabh - 我在上面實現,現在我得到我上面的地圖橫幅區域,但現在我在這句話得到一個錯誤:必需的XML屬性「adSize時」是失蹤。但我已經確定了。我昨天從google獲得了appId,所以我認爲我現在應該工作了?謝謝 –
https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob/banner-xml –
結賬上面的例子..是的,你的應用程序ID現在應該工作。在加載應用程序時也要檢查日誌,因爲有時候廣告請求可以成功加載,但adEngine不會爲您顯示廣告。所以所有這些信息,你會發現在日誌.. –