gpt4 book ai didi

android - 使用 Admob 在 Android 中实现原生广告?可能吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:11 26 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序中实现原生广告。但我只想使用 admob 来做到这一点。我搜索了很多解决方案,但找不到确切的解决方案。

我知道可以使用 MoPub .

我想做的是:在列表项内显示广告,这意味着 ListView/RecyclerView 项之一可以是一个广告,如下图所示。 Image

我找到了一些链接和引用,但这并不能解释原生广告的正确实现。

Link 1 : 原生广告概览

Link 2 : DFP Android 指南 > 定位

Link 3 : DFP 广告管理系统快速入门指南

如果使用 admob 无法做到这一点,MoPub是目前对我来说最好的解决方案。

任何帮助和指导都会有所帮助。谢谢。

最佳答案

最近我遇到了同样的问题。然后我决定将我的解决方案发布到 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();
}

结果如下所示

enter image description here

关于android - 使用 Admob 在 Android 中实现原生广告?可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29232122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com