使用Admob在android中实现本机广告?可能吗?

使用Admob在android中实现本机广告?可能吗?,android,admob,native,ads,mopub,Android,Admob,Native,Ads,Mopub,我正在尝试在我的android应用程序中实现本机广告。但我只想用admob来做。我找了很多解决办法,但找不到确切的办法 我知道可以使用。 我想做的是: 在列表项中显示广告,这意味着列表视图/回收视图项可以是一个广告,如下图所示。 我找到了一些链接和参考资料,但这并不能解释本机广告的正确实现 :本地广告概述 :DFP Android指南>目标设定 :DFP快速入门指南 如果使用admob无法做到这一点,这是目前对我来说最好的解决方案 任何帮助和指导都是有帮助的。谢谢。尝试使用其他广告网络,它提供

我正在尝试在我的android应用程序中实现本机广告。但我只想用admob来做。我找了很多解决办法,但找不到确切的办法

我知道可以使用。

我想做的是: 在列表项中显示广告,这意味着
列表视图
/
回收视图
项可以是一个广告,如下图所示。

我找到了一些链接和参考资料,但这并不能解释本机广告的正确实现

:本地广告概述

:DFP Android指南>目标设定

:DFP快速入门指南

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


任何帮助和指导都是有帮助的。谢谢。

尝试使用其他广告网络,它提供不同类型的本地广告。开发者可以自定义广告的放置和使用位置。例如:如果你需要每隔15行在第二个单元格放置广告,你可以这样使用

规定

 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. 
AvocarrotInstream myAd=new AvocarrotInstream();
myAd.initWithKey(“”);
myAd.setSandbox(真);
myAd.setLogger(真,“全部”);
//填充流内广告
myAd.loadAdForPlacement(此“”);
//将适配器绑定到列表视图组件
.setAdapter(myAd);//在这里,您正在将广告集成到listview
myAd.setFrequency(2,15);//从第二个单元格开始,每隔15个单元格。

这是它提供的列表广告和提要广告。

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

然后你可以显示本地广告

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();

最近我遇到了同样的问题。然后我决定将我的解决方案发布到。希望它能帮助你

基本用法可能如下所示:

    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();
    }
ListView-lvMessages;
AdmobAdapterWrapper适配器振打器;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initListViewItems();
}
/**
*初始化带有项的适配器,用{@link AdmobAdapterWrapper}包装适配器,并将listview设置为此包装
*首先,请注意,下面的代码将在真实的设备上工作,但不适用于模拟器!
*/
私有void initListViewItems(){
lvMessages=(ListView)findViewById(R.id.lvMessages);
//创建适配器时,它也可以是自定义适配器
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple\u list\u item\u 1);
AdapterRapper=新的AdmobAdapterWrapper(此);
AdapterRapper.setAdapter(适配器);//用AdmobAdapterWrapper包装适配器。
//在这里,您可以使用以下字符串为不同类型的本地广告设置自定义布局
//AdapterRapper.setInstallAdsLayoutId(R.layout.your\u installad\u layout);
//AdapterRapper.setcontentAdsLayoutId(R.layout.your\u installad\u layout);
//设置每个数据集的最大ad块数,默认情况下它等于3(根据Admob的策略和规则)
AdapterRapper.setLimitOfAds(3);
//设置ad块之间的数据项数,默认为10。
//您应该根据Admob的政策和规则进行设置,该政策和规则规定不得
//在屏幕可见部分显示多个广告块,
//因此,您应该根据目标设备的项目高度和屏幕分辨率仔细选择此参数
AdapterRapper.setNoOfDataBetweenAds(10);
//这是一个测试admob ID。只有当您准备将产品部署到发行版时,才能将其替换为真实的admob ID!
//否则,您的Admob帐户可能会被禁止
//String admobUnitId=getResources().getString(R.String.banner\u admob\u unit\u id);
//AdapterRapper.setAdmobReleaseUnitId(admobUnitId);
lvMessages.setAdapter(AdapterRapper);//将AdmobAdapterWrapper设置为ListView
//准备收集数据
最终字符串sItem=“item#”;
ArrayList lst=新的ArrayList(100);

对于(int i=1;i,目前仅限于选定的发布商。您需要联系您所在地区的谷歌客户经理进行实施。

嗯,此线程可能已经过时。但从2015年5月开始,到目前为止,AdMob确实支持本机广告(尽管仍处于测试阶段)


此外,在beta测试阶段,它仅对有限数量的开发人员可用。

作为此线程的补充,您现在可以使用NativeExpressAdView按照Google提供的指南非常轻松地为Admob实现NativeAds。 有关更多信息,请查看谷歌文档:

将此代码添加到Listview适配器

       builder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
            @Override
            public void onAppInstallAdLoaded(NativeAppInstallAd ad) {
                FrameLayout frameLayout =
                        (FrameLayout) findViewById(R.id.fl_adplaceholder);
                NativeAppInstallAdView adView = (NativeAppInstallAdView) getLayoutInflater()
                        .inflate(R.layout.ad_app_install, null);
                populateAppInstallAdView(ad, adView);
                frameLayout.removeAllViews();
                frameLayout.addView(adView);
            }
        });

       AdLoader adLoader = builder.withAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(MainActivity.this, "Failed to load native ad: "
                    + errorCode, Toast.LENGTH_SHORT).show();
        }
      }).build();

        adLoader.loadAd(new AdRequest.Builder().build());
对listview适配器进行一些更改,您将从下面的链接获得populateAppInstallAdView()方法

本例涵盖了所有内容,请仔细阅读

添加到混合中,Tooleap Ads SDK提供了一种实现Admob本机Ads的简单方法

他们不再要求您使用传统的listView适配器并在内容中显示广告,而是将admob本机广告显示为一个小的浮动气泡。按下它时,您可以看到完整的本机广告

下面是一个在
活动
类中使用SDK的示例:

BubbleImageAd = new BubbleImageAd(this);
bubbleImageAd.setAdUnitId("YOUR_AD_UNIT_ID");
bubbleImageAd.loadAndShowAd(this);
你可以去看看


是的,您可以在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="320x300"
                    ads:adUnitId="@string/ad_unit_id">

⟩⟩ 在项目结构中,导航到activity_main.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="320x300"
                        ads:adUnitId="@string/ad_unit_id">
</com.google.android.gms.ads.NativeExpressAdView>
⟩⟩ 现在打开MainActivity.java并在公共类中添加以下代码行

private static String LOG_TAG = "EXAMPLE";
NativeExpressAdView mAdView;
VideoController mVideoController;
⟩⟩ 然后在MainActivity.java下添加
<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="320x300"
                    ads:adUnitId="@string/ad_unit_id">
mAdView.setVideoOptions(new VideoOptions.Builder()
    .setStartMuted(true)
    .build());
mVideoController = mAdView.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
@Override
public void onVideoEnd() {
    Log.d(LOG_TAG, "Video playback is finished.");
    super.onVideoEnd();
}
});


mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
    if (mVideoController.hasVideoContent()) {
        Log.d(LOG_TAG, "Received an ad that contains a video asset.");
    } else {
        Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
    }
}
});

mAdView.loadAd(new AdRequest.Builder().build());
<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="320x300"
                        ads:adUnitId="@string/ad_unit_id">
</com.google.android.gms.ads.NativeExpressAdView>
xmlns:ads="http://schemas.android.com/apk/res-auto"
private static String LOG_TAG = "EXAMPLE";
NativeExpressAdView mAdView;
VideoController mVideoController;
// Locate the NativeExpressAdView.
mAdView = (NativeExpressAdView) findViewById(R.id.adView);

// Set its video options.
mAdView.setVideoOptions(new VideoOptions.Builder()
        .setStartMuted(true)
        .build());

// The VideoController can be used to get lifecycle events and info about an ad's video
// asset. One will always be returned by getVideoController, even if the ad has no video
// asset.
mVideoController = mAdView.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
    @Override
    public void onVideoEnd() {
        Log.d(LOG_TAG, "Video playback is finished.");
        super.onVideoEnd();
    }
});

// Set an AdListener for the AdView, so the Activity can take action when an ad has finished
// loading.
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        if (mVideoController.hasVideoContent()) {
            Log.d(LOG_TAG, "Received an ad that contains a video asset.");
        } else {
            Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
        }
    }
});

mAdView.loadAd(new AdRequest.Builder().build());
<string name="ad_unit_id">ca-app-pub-39402560999xxxxx/21772xxxxx</string>
<uses-permission android:name="android.permission.INTERNET" />
//adding native templates
implementation project(':nativetemplates')