我一直在試圖從admob實現原生廣告。Android原生廣告admob
我得到了一些示例代碼Github。我試圖實現這個代碼,並且演示代碼工作正常。原生廣告正常顯示。
然後我創建了自己的AdMob帳戶並獲得一個Ad Unit ID
。以前的原生廣告演示代碼無法使用此ID,並且出現錯誤代碼0
,儘管我創建的Ad Unit ID
適用於橫幅廣告類型。
有人可以幫我嗎?
我一直在試圖從admob實現原生廣告。Android原生廣告admob
我得到了一些示例代碼Github。我試圖實現這個代碼,並且演示代碼工作正常。原生廣告正常顯示。
然後我創建了自己的AdMob帳戶並獲得一個Ad Unit ID
。以前的原生廣告演示代碼無法使用此ID,並且出現錯誤代碼0
,儘管我創建的Ad Unit ID
適用於橫幅廣告類型。
有人可以幫我嗎?
當我第一次實施從我的新創建AdMob帳戶AdMob的,花了我的帳戶2天,終於得到了廣告,所以不要擔心,只是等待......如果還沒有新創建的帳戶,然後看看你添加了這個許可或不
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
我也這樣做了,但沒有工作。我想提一下它的原生廣告,而不是橫幅廣告。我甚至不確定Google是否已經在admob中發佈了對原生廣告的支持。 –
確定做了一件事,僅用於測試目的,請問您的admod賬戶已經使用了一段時間了。以他們的AdMob ID之一爲例,看看你是否收到廣告。沒關係,這是什麼類型的廣告 – penta
試試下面的代碼:
XML文件:
<com.google.android.gms.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentBottom="true"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-xxxxxxxxx" />
的的.java類:
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("B2D638A0BEECBE3464024D83BE163E0E")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
確保打開註釋行:
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("B2D638A0BEECBE3464024D83BE163E0E")
當你在調試模式在調試模式下真正的廣告 .Clicks可能導致阻塞AdMob帳戶。你會得到你的logcat的爲TestDevice ID,請更換與該礦山。
定義您的manifest.xml以下
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
,也是許可:
<uses-permission android:name="android.permission.INTERNET" />
,你準備好去。
**注:**如果廣告沒有顯示出來,然後等待ATLEAST 30分鐘。
我真的很感謝你的幫助,但實際上是在處理「原生廣告」。你可以通過這個鏈接進行搜索。 https://developers.google.com/mobile-ads-sdk/docs/dfp/android/native?hl=zh-CN –
最近我stucked同樣的問題。然後我決定將我的解決方案發布到admobadapter。希望它能幫助你。
的基本用法可能看起來像:
ListView lvMessages;
AdmobAdapterWrapper adapterWrapper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initListViewItems();
}
/**
* Inits an adapter with items, wrapping your adapter with a {@link AdmobAdapterWrapper} and setting the listview to this wrapper
* FIRST OF ALL Please notice that the following code will work on a real devices but emulator!
*/
private void initListViewItems() {
lvMessages = (ListView) findViewById(R.id.lvMessages);
//creating your adapter, it could be a custom adapter as well
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
adapterWrapper = new AdmobAdapterWrapper(this);
adapterWrapper.setAdapter(adapter); //wrapping your adapter with a AdmobAdapterWrapper.
//here you can use the following string to set your custom layouts for a different types of native ads
//adapterWrapper.setInstallAdsLayoutId(R.layout.your_installad_layout);
//adapterWrapper.setcontentAdsLayoutId(R.layout.your_installad_layout);
//Sets the max count of ad blocks per dataset, by default it equals to 3 (according to the Admob's policies and rules)
adapterWrapper.setLimitOfAds(3);
//Sets the number of your data items between ad blocks, by default it equals to 10.
//You should set it according to the Admob's policies and rules which says not to
//display more than one ad block at the visible part of the screen,
// so you should choose this parameter carefully and according to your item's height and screen resolution of a target devices
adapterWrapper.setNoOfDataBetweenAds(10);
//It's a test admob ID. Please replace it with a real one only when you will be ready to deploy your product to the Release!
//Otherwise your Admob account could be banned
//String admobUnitId = getResources().getString(R.string.banner_admob_unit_id);
//adapterWrapper.setAdmobReleaseUnitId(admobUnitId);
lvMessages.setAdapter(adapterWrapper); // setting an AdmobAdapterWrapper to a ListView
//preparing the collection of data
final String sItem = "item #";
ArrayList<String> lst = new ArrayList<String>(100);
for(int i=1;i<=100;i++)
lst.add(sItem.concat(Integer.toString(i)));
//adding a collection of data to your adapter and rising the data set changed event
adapter.addAll(lst);
adapter.notifyDataSetChanged();
}
而且結果會像this
傢伙,我都面臨着同樣的問題,最後我有一個解決方案,它希望這將你們..:)
在這裏,當你試圖創建一個adUnitId設置確保該寬度和高度這裏將是在XML文件中相同的寬度和高度,這樣
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="360x320"
ads:adUnitId="@string/NativeAdId">
</com.google.android.gms.ads.NativeExpressAdView>
此圖像中
還有一件事,你必須記住,你的 將使廣告的寬度和高度將適合你的XML佈局,所以對於這個只是 首先嚐試它在你的XML,然後創建一個原生廣告d爲此。
只要嘗試一下,隨時告訴我你是否會在做這些之後遇到任何問題。謝謝
同樣在這裏好友我想我們是在同一條軌道上 –
請分享您的代碼 – kgandroid
以下是github @kgandroid中的類的鏈接:https://github.com/googleads/googleads-mobile-android-示例/ blob/master/admob/NativeExample/app/src/main/java/com/google/example/gms/nativeexample/MainActivity.java –