Android : Why exactly am I not seeing admob ads?

on Tuesday, July 8, 2014


I'm not yet experienced enough with admob to know where my issue is and why no ads are being shown. This is the first time I am using Google Play Services.


After importing Google Play Services library, I started to follow the tutorial on libgdx github


https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx


The only thing is, for some reason, not all of the code on the wiki works in my project, giving me errors for various reasons. I did my best job googling and using my Java knowledge to improvise and create equivalent code without the errors. What I ask is, can someone, who has admob working correctly, compare their code with mine?


It would be greatly appreciated.


Thanks,


-Steve



AndroidLauncher.java

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdRequest.Builder;
import com.google.android.gms.ads.AdView;
import com.valgriz.adsetup.AdSetup;

public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

RelativeLayout layout = new RelativeLayout(this);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

View gameView = initializeForView(new AdSetup());

AdView adView = new AdView(this);
adView.setAdUnitId("10 DIGIT LONG ADID");
adView.setAdSize(new com.google.android.gms.ads.AdSize(
AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT));

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("037c620042a09058").build();

adView.loadAd(adRequest);

layout.addView(gameView);

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

layout.addView(adView, adParams);

setContentView(layout);
}
}





Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.valgriz.adsetup.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name="com.valgriz.adsetup.android.AndroidLauncher"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>

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

0 comments:

Post a Comment