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

Amr*_*dri 10 android native ads admob mopub

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

我知道可以使用MoPub.

我想要做的是:在列表项中显示广告,这意味着其中一个ListView/ RecyclerView项可以是一个广告,如下图. 图片

我找到了一些链接和参考,但这并不能解释原生广告的正确实施.

链接1:原生广告概述

链接2:DFP广告管理系统Android指南>定位

链接3:DFP快速入门指南

如果使用admob无法做到这一点,MoPub现在是最好的解决方案.

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

kot*_*107 6

最近我坚持同样的问题.然后我决定将我的解决方案发布到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();
    }
Run Code Online (Sandbox Code Playgroud)

结果将类似于以下

在此输入图像描述


Sha*_*dow 5

尝试使用其他一些广告网络,它提供不同类型的原生广告.开发人员可以自定义广告的放置和使用位置.例如:如果您需要每15行在第二个单元格中放置广告,您可以这样使用.

Avocarrot 提供了这一点.

 AvocarrotInstream myAd = new AvocarrotInstream(<yourListAdapter>);
  myAd.initWithKey( "<your API Key>" );
  myAd.setSandbox(true);
  myAd.setLogger(true ,"ALL"); 

// Populate with In-Stream ads
 myAd.loadAdForPlacement(this,  "<your Placement Name>" );
// Bind the adapter to your list view component
<yourListView>.setAdapter(myAd);// here you are integrating ads to listview
 myAd.setFrequency(2,15); // every 15 cells starting from the 2nd cell. 
Run Code Online (Sandbox Code Playgroud)

以下是提供列表广告和Feed广告的文档.


Jam*_*ken 5

原生广告与其他DFP/AdMob广告一起包含在Google Play服务中.确保在您的列表中列出了以下依赖项build.gradle(请注意,7.5.0是此发布时的最高版本).

compile "com.google.android.gms:play-services-base:7.5.0"
compile "com.google.android.gms:play-services-ads:7.5.0"
Run Code Online (Sandbox Code Playgroud)

然后,您可以展示原生广告

AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
    .forAppInstallAd(new OnAppInstallAdLoadedListener() {
        @Override
        public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
            // Show the app install ad.
        }
    })
    .forContentAd(new OnContentAdLoadedListener() {
        @Override
        public void onContentAdLoaded(NativeContentAd contentAd) {
            // Show the content ad.
        }
    })
    .withAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            // Handle the failure by logging, altering the UI, etc.
        }
    })
    .withNativeAdOptions(new NativeAdOptions.Builder()
            // Methods in the NativeAdOptions.Builder class can be
            // used here to specify individual options settings.
            .build())
    .build();
Run Code Online (Sandbox Code Playgroud)

单击此处获取完整文档.


Hou*_*ine 3

作为此线程的补充,您现在可以按照 Google 使用 NativeExpressAdView 提供的指南非常轻松地实现 Admob 的 NativeAds。有关更多信息,请查看谷歌文档: https://firebase.google.com/docs/admob/android/native-express ?hl=en