After debugging i found out that my onLoaded()
return is false and only a blank white screen appears.
No add is getting loaded! even if i wait for infinite time
the add unit id is picked from
https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial (for sample add) Here is my MainActivity class
package com.example.jatinarora.threestickhockey;
import android.app.ActionBar;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.media.MediaPlayer;
import android.os.SystemClock;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
public class MainActivity extends ActionBarActivity {
public InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WindowManager.LayoutParams.FLAG_FULLSCREEN);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
requestNewInterstitial();
float count123 = 1 ;
// i tried setting the loop to infinity to wait for the advertisment to load!
while(count123 >=0) {
if (interstitial!= null && interstitial.isLoaded()) {
interstitial.show();
count123 = -1;
}
}
}
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
protected void onResume() {
super.onResume();
mView.running = true;
}
protected void onPause()
{
mView.resume = 1;
mView.running = false;
super.onPause();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}
In my activity_main.xml
I didn't add AdView because in all the tutorials and links i have visited,I haven't seen any for interstitial , It was used for banner
Here is my activity_main.xml
<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:paddingLeft="0dp"
android:label="@string/app_name"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp" tools:context=".MainActivity">
<com.example.jatinarora.threestickhockey.mView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
Here is my manifestFile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jatinarora.threestickhockey" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
</manifest>
Any suggestion ,mistake why the add is not showing up or any alternate solution will be helpful a lot!