Implementing native ads in android using Admob? is it possible?
Asked Answered
D

13

10

I'm trying to implement native ads in my android application. But I want to do it using admob only. I searched a lot for solution but could not find exact one to do so.

I know it is possible using MoPub.

What I wanted to do is this: Show ads inside list item which means one of the ListView/RecyclerView item can be one ad like below image. Image

I found some links and references but that doesn't explain proper implementation of the native ads.

Link 1 : Native ads overview

Link 2 : DFP Android Guides > Targeting

Link 3 : DFP Quick Start Guide

If it is not possible to do it using admob, MoPub is best solution for me right now.

Any help and guidance would be helpful. thanks.

Delusive answered 24/3, 2015 at 12:0 Comment(4)
Whats wrong with the official docs?Grating
@TimCastelijns: nothing is wrong with that but I'm unable to implement native ads using admob. can you share any example? how to do?Delusive
It's currently in beta. You can implement it yourself, but cannot publish the app, as you cannot obtain a production ad id for your app. Hopefully they'll release it this month or in October.Middlebuster
January 2016 and still not published... They don't even give a release date.Trabzon
H
3

As an addition to this thread, you can now implement NativeAds for Admob very easily by following the guide provided by Google using NativeExpressAdView . For more information, check the google documentation : https://firebase.google.com/docs/admob/android/native-express?hl=en

Holms answered 19/5, 2016 at 14:27 Comment(0)
L
6

Recently I stucked with the same question. Then I decided to post my solution for that to admobadapter. Hope it will help you.

The basic usage could look like:

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

And the result will look like the following

enter image description here

Lox answered 4/9, 2015 at 10:40 Comment(5)
Really simple and good adpater but I have a question generally about admob an native ads. In admob where I create ads I only have options of banner and interstellar.. How can I request native ads?Margaritamargarite
@TadejVengust, Hi, thx. Actually there's no a way to request real native ads from Google Ads server but only test ones. The Native Ads feature is still in the beta-release state. At the moment you could request it with a reserved admob unit id 'ca-app-pub-3940256099942544/2247696110' from the Google Ads docs. Please refer to the git repo to get a working example...Lox
Thank you for the answer. So basically I cant use then im release apps until they are out of beta testing? On a different note - if I read your post correctly, admobadapter is your solution? I posted a git request of a feature that would really help me if you maybe have time to look at it?Margaritamargarite
@TadejVengust Welcome! Yeah, I guess we have had a conversation on this feature already. You are MoMannn, right? We can proceed discussing in your issue then:)Lox
Please do not copy your answer from other threads. Make a link instead please.Mucin
T
5

Try using some other ad networking where it provides different types of native ads. Developers can customize the ads where to place and use it. For eg: if you need to place ads at second cell every 15 row, you can use like this.

Avocarrot provides that.

 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. 

Here is Documentation it provides List ads and Feed ads.

Twit answered 24/3, 2015 at 12:22 Comment(0)
P
5

Native ads are included in Google Play Services along with the rest of DFP/AdMob advertising. Make sure you have the following listed as dependencies in your build.gradle (note that 7.5.0 is the highest version as of this posting).

compile "com.google.android.gms:play-services-base:7.5.0"
compile "com.google.android.gms:play-services-ads:7.5.0"

Then you can display native ads

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

Click here for complete documentation.

Pinpoint answered 13/7, 2015 at 20:46 Comment(1)
Is there any complete example in listview @James ?Psychoneurosis
H
3

As an addition to this thread, you can now implement NativeAds for Admob very easily by following the guide provided by Google using NativeExpressAdView . For more information, check the google documentation : https://firebase.google.com/docs/admob/android/native-express?hl=en

Holms answered 19/5, 2016 at 14:27 Comment(0)
S
2

Add this code to your Listview Adapter

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

Make some changes for listview Adapter and you will get populateAppInstallAdView() method from below link

Everything is covered in this example please go through this https://github.com/googleads/googleads-mobile-android-examples/tree/master/admob

Salve answered 28/7, 2016 at 8:36 Comment(0)
S
2

Adding to the mix, Tooleap Ads SDK provides a simple way to implement Admob's native ads.

Instead of requiring you to use the traditional listView adapter and showing the ad inside you content, they are showing admob native ads as a small floating bubble. When pressing on it you can see the full native ad.

Here is an example of using their SDK inside your activity class:

BubbleImageAd = new BubbleImageAd(this);
bubbleImageAd.setAdUnitId("YOUR_AD_UNIT_ID");
bubbleImageAd.loadAndShowAd(this);

You can check them out here.

enter image description hereenter image description here

Southwester answered 12/3, 2017 at 17:54 Comment(0)
M
2

This is working for me:

  1. Copy Native template in project library.

  2. in Build.gradle(Module:Appname) - add this:

    implementation project(':nativetemplates')
    implementation 'com.google.android.gms:play-services-ads:20.4.0'
    
  3. in Setting.gradle(Appname) - add this:

    include ':nativetemplates'
    
  4. in Mainfest - update as earlier.

    Before Application:

    <meta-data
     android:name="com.google.android.gms.ads.APPLICATION_ID"
     android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    

    add this Permission:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    
  5. In Layout file add this:

    <com.google.android.ads.nativetemplates.TemplateView
     android:id="@+id/my_template"
    app:gnt_template_type="@layout/gnt_medium_template_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    </com.google.android.ads.nativetemplates.TemplateView>
    
  6. In program file:

    MobileAds.initialize(this)
    //build ad
    val adLoader = AdLoader.Builder(this,"ca-app-pub-3940256099942544/2247696110")
        .forNativeAd {
            val style  = NativeTemplateStyle.Builder().withMainBackgroundColor(ColorDrawable(Color.WHITE))
                .build()
            val template = findViewById<TemplateView>(R.id.my_template)
            template.setStyles(style)
            template.setNativeAd(it)
        }.build()
    //show ad
    adLoader.loadAd(AdRequest.Builder().build())
    

If still not loading, Check with your admod credentials.

Mixer answered 18/11, 2021 at 13:52 Comment(0)
C
1

Well, this thread is probably outdated. But starting May 2015, and as of now, AdMob does support native ads (still in beta though).

https://support.google.com/admob/answer/6239795

Also it's available only to a limited number of developers as of its beta stage.

Clavius answered 29/4, 2016 at 15:13 Comment(0)
P
1
Admob in your android these are the codes needed. 
    <com.google.android.gms.ads.AdView
              android:layout_alignParentBottom="true"
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="ca-app-pub-4549020480017205/6066702579"
                />

//In your java class file

     AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
Pangermanism answered 6/3, 2017 at 11:49 Comment(0)
D
1

⟩⟩ In project structure, navigate to activity_main.xml and paste the following code in your layout.

<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>

and in the same file i.e activity_main.xml add below lines of code in the header part

xmlns:ads="http://schemas.android.com/apk/res-auto"

⟩⟩ Now open MainActivity.java and add below lines of code in public class

private static String LOG_TAG = "EXAMPLE";
NativeExpressAdView mAdView;
VideoController mVideoController;

⟩⟩ Then under MainActivity.java and add below lines of code in onCreate() method.

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

⟩⟩ Now open string.xml file in values folder and paste the below line of code.

<string name="ad_unit_id">ca-app-pub-39402560999xxxxx/21772xxxxx</string>

⟩⟩ Then open the Manifest file and add Internet permission to it.

<uses-permission android:name="android.permission.INTERNET" />

THE RESOURCE : How to insert AdMob Native Ad in your Android App

Dandridge answered 29/10, 2019 at 17:23 Comment(0)
D
0

It is restricted to selected publishers at the moment. You'll need to contact a Google account manager in your region for implementation.

Durware answered 29/3, 2016 at 8:19 Comment(0)
S
0

Yes it is possible you can use below code in xml file

<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());
Sada answered 19/11, 2018 at 13:10 Comment(0)
D
0

To add Native Templates in our app we have to follow some basic steps:

1-First, we have to download the Native Templates, so got to developers.google

2-Then click on the Download Native Templates, now you will be directed to Github

3-Then download the zip file from GitHub and extract the zip file to any folder and remember the location of the folder, we will use it later

4-Now go inside Android studio and click on File->New->Import Module, Now you will see a new window (Import-Module from Source) Now click on the Browse icon and select the nativetemplates folder and click on finish and wait for Gradle build to finish.

5-Now open the Gradle Scripts->build.gradle (Module: app) section and import the nativetemplates project and click the "sync Now" show at the top as shown below:

//adding native templates
implementation project(':nativetemplates')

https://www.studytonight.com/post/how-to-add-admob-native-ad-in-android-app#

Dandridge answered 15/12, 2020 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.