Admob Interstitial Ad non clickable - android

I created a Android Game and the issue i am using both Banner ad and a Interstitial ad
1) Banner ad shows while playing the game and 2) Interstitial Ad shows when player ends up winning a level but the problem i am facing is admob interstitial ad is showing up but one cannot click it, it only display at the level end but user not able to click it i tried searching around but couldn't find the solution for it,
Please help with it
These are the source usage of the ad code in the game
The Activity file :
public class APP extends Activity
{
private InterstitialAd interstitial;
}
public static void showInterAd(){
((APP)APP.ctx).showAd();
}
// BANNER AD
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ctx = this;
setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(adRequest);
}// INTERSTITIAL AD
public void showAd(){
((Activity)ctx).runOnUiThread(new Runnable() {
#Override
public void run() {
// Create the interstitial.
interstitial = new InterstitialAd(APP.this);
interstitial.setAdUnitId("ca-app-pub-ID");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
// Set the AdListener.
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if (interstitial.isLoaded()) {
interstitial.show();
I am calling the Ad code in different file :
levelCompleted = true;
endOfGame = true;
soundManager.playSound(APP.SOUND_WON);
APP.showInterAd();
}
The Manifest File :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XYZ"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:required="false" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
android:required="false" />
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"
android:required="false" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="false" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<activity
android:name="com.xyz.APP"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboard"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.XYZ.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</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" />
</application>
</manifest>

Remove :
android:launchMode="singleInstance" from Manifest File.

OK you have many problems with your code. I suggest you start by following the examples on https://developers.google.com/mobile-ads-sdk/docs/admob/advanced.
Several things you really need to fix:
Get rid of static attributes and methods in your Activity. Eg showInterAd()
Create your interstitial in Activity.onCreate(), load it before your game, show it after your game.

Related

Admob interstitial ads issue?

I am making a simple app, in this app I am add a navigation drawer & drawer item have contain website url link when I click navigation item it was open another brawser with url that I have given & I am put google admob ads in this app so when I click on this item page was open with admob interstitial ads nice but my problem is when ad was shown I am click back button ad was close & again my app is open but I want to shown that page (my url shown in browser) but it now happen again open my app when I close the admob interstitial ads. How to fix that pronlem, please any one help me.
watch video for better understand : https://drive.google.com/open?id=0B8YTgurIRbm5SS01YW1WRHptYlU
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="26" />
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="#mipmap/logo_icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/logo_circle"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SpleshScreen.SpleshScreen"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize">
</activity>
<service android:name=".Messaging.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent"
android:noHistory="true"/>
</application>
You need to implement the adListner() for the ads, put this in your code after you initialize your Interstitial Code
InterstitialAd mInterstitialAd = new InterstitialAd(getActivity());
mInterstitialAd.setAdUnitId(mContext.getString(R.string.admob_ad_unit_id_interstitial));
mInterstitialAd.loadAd(new AdRequest.Builder().
build());
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
super.onAdClosed();
// perform your task after the ad is closed
Intent intent = new Intent(CurrentAct.this, GoToAct.class);
startActivity(intent);
// load the ad again if you need to show it again
mInterstitialAd.loadAd(new AdRequest.Builder().
build());
}
#Override
public void onAdLoaded() {
super.onAdLoaded();
}
});
// open your ad
btnclick(){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
// if your ad is not ready to be shown, perform your task here
Intent intent = new Intent(CurrentAct.this, GoToAct.class);
startActivity(intent);
}
}

Admob ads not displayed

I have a game on Google Play it was showing ads (Banner ads) now there is no ads are displayed
What are the possible causes ?
In build.gradle I have this:
com.google.android.gms:play-services-ads:9.2.0
the latest version is 9.4.0 could this be a possible cause ? But in this way if it is a cause I should update my app for each update of google-play-services
Another thing: I put ads in play screen so player see ads most of the time Is this a problem as I read something about accidental clicks within Admob policies
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mygdx.clockspuzzle"
android:versionCode="3"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="Clocks Puzzles"
android:theme="#style/GdxTheme" >
<activity
android:name="com.mygdx.clockspuzzle.AndroidLauncher"
android:label="Clocks Puzzles"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<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" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
AndroidLauncher class:
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// gameView
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new GameMain(this), config);
// adView
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
AdRequest.Builder builder = new AdRequest.Builder();
adView.loadAd(builder.build());
// add gameView
layout.addView(gameView);
// add adView
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView, adParams);
setContentView(layout);
}
the point that I am talking about is ads were displayed correctly without a problem.

Admob not show in lollipop 5.1 device

hello friends i wnat ot integrate admob in my application so i set following code for that
Main.java
public class Main extends Activity{
AdView adView;
RelativeLayout mRelativeLayoutRoot;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.advs);
mRelativeLayoutRoot=(RelativeLayout)findViewById(R.id.root);
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(getResources().getString(R.string.admob_unit_id));
adView.setId(11);
LayoutParams lp;
lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); // You might want to tweak these to WRAP_CONTENT
lp.addRule(mRelativeLayoutRoot.ALIGN_PARENT_BOTTOM);
mRelativeLayoutRoot.addView(adView, lp);
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".Main"
android:label="#string/app_name" >
<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>
</manifest>
When i run above code advertisement show only Jellybean , kitkat mobile device in Lolliop device 5.1 it is not showing any idea how can i solve this problem ?
EDIT
When i run this cod ein Micomax android one phone (Lollipop 5.1) it is not show advertise on that
Suggest you start by creating your AdView in the XML layout for your Activity rather than in code. It will help eliminate a few potential errors.
Next, make sure that you have added the deviceIds for the 2 devices as test device ids.
Finally, look at your logcat for the 2 devices and see what the Admob log says in the case when the ad does not load.

admob interstitial ad shows after minute it should

I'm making a 2D game in Unity3D. When a main character dies, a menu with "restart" ( which is Application.LoadLevel("thisLevel")) and "go to main menu" options appears. But I need interstitial ad to appear before menu (Character dies => ad appears). I did it. But here is the problem: Character dies, interstitial ad appears, I close it, press restart button in menu, I make character die again, and ad appear just after 1-2 minutes, which is strange. Then I press restart and make character die again, it appears instantly, as it should be. But if I don't wait for ad after second "death" ad does not appear after third "death" and so on. Here is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.SocialPlatforms;
using GoogleMobileAds.Api;
public class AdBehaviourScript : MonoBehaviour {
private const string INTERSTITIAL_ID = "ca-app-pub-myNumers";
public InterstitialAd interstitial;
private bool showed;
void Start () {
DontDestroyOnLoad(transform.gameObject);
showed = false;
interstitial = new InterstitialAd(INTERSTITIAL_ID);
AdRequest request2 = new AdRequest.Builder().Build();
interstitial.LoadAd(request2);
}
void Update () {
}
public void showAd () {
if (interstitial.IsLoaded() && !showed) {
interstitial.Show();
showed = true;
}
}
public void destroyAd () {
interstitial.Destroy();
}
}
I call functions from this script when character dies. Here is my manifest file if you need:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.example.admobtest" android:versionName="1.0" android:versionCode="1">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<!-- Google Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false">
<!-- meta-data tag for Google Play services -->
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<meta-data android:name="android.app.lib_name" android:value="unity" />
</activity>
<activity android:name="com.unity3d.player.VideoPlayer" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigaton|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
</activity>
<!-- Google Mobile Ads Activity -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigati on|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>
What is my problem?
Try hiding the ad instead of destroying it
You should check isInterstitialReady before displaying the ad.
Actually what happens is that when an ad is displayed then the admob plugin start downloading new ad. due to which when you call the ad the second time it is not yet downloaded and displays after a sec. You should check if your ad is ready then dislpay your ad.

phonegap app loads first page upon screen orientation change

i am developing an android app using phonegap. i have multiple pages in the app and a single activity. whenever i change the orientation of the device, no matter which page i am on, the app loads the first page which is shown when the app is launched. i assumed it was because i had not overriden the onResume() method in the activity, but even that failed to solve the problem.
EDIT: This issue does not arise if the app is paused and the resumed.
My activity:
public class MainScreen extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/landing.html");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
}
EDIT: Added Manifest file
My Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.code"
android:versionCode="5"
android:versionName="1.4" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.miniorange.authenticator.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.miniorange.authenticator.MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name="com.miniorange.authenticator.MainScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.plugin.gcm.PushHandlerActivity"/>
<receiver android:name="com.plugin.gcm.CordovaGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.me.code" />
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />
</application>
</manifest>
what may be the solution to this problem?
sorry ... ( answering it late :D )
I had this problem with my app :
When I change the orientation, activity reloads ...
And I found this solution :
add this attribute to your <activity> tags :
android:configChanges="orientation"
suggestion ... use this insted (better) :
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
==========================================
information about solution :
what is the reason .. (?)
It'll say to application that you want to handle this changes (orientation, keyboardHidden, keyboard, screenSize, locale, etc.) yourself.

Categories

Resources