libGDX Native Ads Express

Anything libgdx related goes here!

libGDX Native Ads Express

Postby mmicoe » Sat Oct 01, 2016 7:33 am

Hi, I am testing native ads in libGDX but I cannot view the ad-layout on the screen:
The activity_main_layout.xml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context="com.mmicoe.testing.android.AndroidLauncher">

    <com.google.android.gms.ads.NativeExpressAdView
        android:id="@+id/adView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="320x150"
        ads:adUnitId="ca-app-pub-xxxxxxx/xxxxxxxx">
    </com.google.android.gms.ads.NativeExpressAdView>
</RelativeLayout>



The AndroidLauncher:

Code: Select all
public class AndroidLauncher extends AndroidApplication{

   RelativeLayout layout = new RelativeLayout(this);
    View gameView = initializeForView(new G1(this,this),config);
   
    layout.addView(gameView);

                  RelativeLayout.LayoutParams adParams =
                   new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                   RelativeLayout.LayoutParams.WRAP_CONTENT);
           adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
           adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

           //NATIVE-ADS-------------------------------------------------------------------
      NativeExpressAdView adViewN = (NativeExpressAdView)findViewById(adView4);
      AdRequest request = new AdRequest.Builder().addTestDevice("1XXXXXXXXXXXXXXXXXXXX").build();
      adViewN.loadAd(request);

      layout.addView(adViewN, adParams);

           // Hook it all up
           setContentView(layout);

}


I get the issue:
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.NativeExpressAdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference

How can I to add the layout findViewById(adView4); into layout ?
Regards,
mmicoe
 
Posts: 163
Joined: Tue Dec 10, 2013 11:28 pm
Location: Spain

Re: libGDX Native Ads Express

Postby MMM1412 » Thu Aug 15, 2019 8:14 am

I have same problem. Now Admob native advance ads become more popular, Admob let me use this last week. I hope Libgdx team have a instruction to attack native advance ads into Libgdx Game. Because profit from Native ads is very hopeful.

At least, Admob team created a native ads template. We just use it.
Code: Select all
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity"
   tools:showIn="@layout/activity_main" >

<!--  This is your template view -->
<com.google.android.ads.nativetemplates.TemplateView
   android:id="@+id/my_template"
   <!-- this attribute determines which template is used. The other option is
    @layout/gnt_medium_template_view -->
   app:gnt_template_type="@layout/gnt_small_template_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />

...
</LinearLayout>
MMM1412
 
Posts: 119
Joined: Mon Sep 14, 2015 10:48 am


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 1 guest