Unable to close AdMob interstitial ad - android

Lately, my android app has been showing Admob interstitial ads that cannot be dismissed. It seems the back button action to dismiss an ad was discontinued. Most interstitial ads include a "Close" button on the ad itself, but not all of them do. When an interstitial ad is delivered without a close button, the only way to close the ad is to kill the app.
Here is an example of an ad we received without a close button:
I am using
implementation 'com.google.android.gms:play-services-ads:17.0.0'
in my Gradle build.
So the question is: Is there any way to close an interstitial ad aside from pressing the close button on the ad?

If the interstitial should be cropped so that the close button does not appear, it may be due to the max_aspect setting in your AndroidManifest.
For Interstitial the android.resizeableActivity setting has to be true.
In may application I have set the android.resizeableActivity=true in the application tag
but set my android.max_aspect to 1.8 which is needed for my game.
And only in my main acticity tag i set the android:resizeableActivity="false"
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:resizeableActivity="true"
>
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admob_App_id" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data android:name="android.max_aspect" android:value="1.8" />
<activity
android:name="com.entwicklerx.macedefense.MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"
android:resizeableActivity="false">
I hope this helps someone who has stumbled into the same problem as I recently

It seem like AdMob did some A/B testing on Back button (back button closed the Ads for some users and did not do anything for other users) but now it seems that AdMob chose the later option (back button do nothing)
I noticed this with some Ads, most probably it is an AdMob bug related to certain Ads creative sizes on some phones.
Also I've noticed that it stopped happening using newer SDK versions.

Interstitital ads can be closed by back button.
Remove all minterstitial.loadad code, and also showad code , which you call fram callback you implemented , like onadclose callback.
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-........");
// mInterstitialAd.setAdUnitId("ca-app-pub-......."); /// test ads
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener(){
#Override
public void onAdLoaded() {
super.onAdLoaded();
mInterstitialAd.show();
}
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
}
#Override
public void onAdClicked() {
super.onAdClicked();
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
super.onAdOpened();
}
});
}
});

Related

Interstial ad not loading after app reinstall or boot in Android API 27 in emulator

In my app if I make an app reinstall by drag and drop of the apk in the emulator or start app after restarting the emulator by ad never loads.
I've tried to investigate the cause but the cause just looks like, in this cases, Android "forgets" that the interstitial ad exists, as stupid as it might sound:
interstitialAds.loadAd(adr);
CountDownTimer mcdf=new CountDownTimer(600000,5000) {
#Override
public void onTick(long l) {
if (interstitialAds.isLoading()) {
Toast.makeText(getBaseContext(), "Ad loading", Toast.LENGTH_LONG).show();
}
if (interstitialAds.isLoaded()) {
Toast.makeText(getBaseContext(), "Ad loaded", Toast.LENGTH_LONG).show();
}
}
#Override
public void onFinish() {
if (!interstitialAds.isLoaded()) {
interstitialAds.loadAd(adr);
}
}
}.start();
What I get is a behavior which displays 3 times "Ad loading" and after that no more Toasts are displayed, on the other hand if I execute the program for a second time I get the expected behavior: "Ad loading" displays 1 or 2 times and the rest of the time "Ad loaded" displays periodically.
My bets now are into that this is an emulator bug, but maybe I'm missing something.
I think the best way to help me with this question would be for someone who has an API 27 physical device to check that an interstitialAd loads under the described situations (app reinstall while the previous one is still installed and after a boot).
The interstitial ad is defined this way in my manifest, just in case that were to have any effect:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
tools:replace="android:theme"
/>

Cannot show video ads from Smaato Ads for my Android App

I am trying to implement Smaato Video Ads on my Android App.
I have followed the instructions from the Smaato page and the Smaato example app and yet, I cannot manage to show the Smaato Video Ads.
The code that apparently should show a video ad in fullscreen is:
private static Video smaatoVideoAd; // A Smaato Video global variable
smaatoVideoAd = new Video(this.getApplicationContext());
smaatoVideoAd.getAdSettings().setPublisherId(0); //int of 0 is supposedly a test mode
//smaatoVideoAd.getAdSettings().setPublisherId(PublisherID);
smaatoVideoAd.getAdSettings().setAdspaceId(0); //int of 0 is supposedly a test mode
//smaatoVideoAd.getAdSettings().setAdspaceId(VideoAd_ID);
smaatoVideoAd.setVastAdListener(this);
smaatoVideoAd.setAutoCloseDuration(5);
smaatoVideoAd.disableAutoClose(true);
smaatoVideoAd.setVideoSkipInterval(3);
} // End of onCreate
// Called when the video has been loaded.
#Override
public void onReadyToShow() {
// Call this when you want to show the video ad.
smaatoVideoAd.show();
}
#Override
public void onWillShow() {
// Called when the ad will show.
}
#Override
public void onWillOpenLandingPage() {
// Called when the banner has been clicked.
}
#Override
public void onWillClose() {
// Called when Interstitial ad will be closed.
}
#Override
public void onFailedToLoadAd() {
// called when video failed to load.
}
The Smaato libs for build.gradle has been setup, and that is pretty straightforward and short:
repositories {
...
flatDir {
dirs 'libs'
}
...
}
dependencies {
...
implementation name:'SOMAAndroid-9.1.3-release', ext:'aar'
...
}
And in the AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />
<meta-data android:name=”com.google.android.gms.version” android:value=”#integer/google_play_services_version”/>
<activity android:name="com.smaato.soma.interstitial.InterstitialActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />
<activity android:name="com.smaato.soma.video.VASTAdActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />
<activity android:name="com.smaato.soma.ExpandedBannerActivity" android:resizeableActivity="false" android:screenOrientation="landscape" />
Besides, Smaato declares that: "Since v8.0.0, the Smaato Android SDK contains an automatic initialization routine. Therefore there is no need for publishers to manually call an additional SDK initialization method".
But running this code, gives me the following alert in the Logcat:
SOMA_VIDEO: Video must be loaded before showing it
So, the video add is not loading at all. What am I missing here?
Can you help me? Thanks.
Solved! Apparently, I hadn't the correct sequence order. With this order, the warning in Logcat vanishes:
smaatoVideoAd = new Video(this.getApplicationContext());
smaatoVideoAd.setVastAdListener(this);
smaatoVideoAd.setAutoCloseDuration(3);
smaatoVideoAd.disableAutoClose(false);
smaatoVideoAd.setVideoSkipInterval(1);
smaatoVideoAd.getAdSettings().setPublisherId(0); // Trial Publisher Id: 0
smaatoVideoAd.getAdSettings().setAdspaceId(3090); // Trial Adspace Id for video: 3090
smaatoVideoAd.asyncLoadNewBanner();
Notice that the code for Smaato video ad in trial mode is 3090, not 0. Also, I have put the Smaato Ad in a new activity, so closing the ad will close the child activity and not my main one.

AdActivity leak on AdMob (SDK 7.0) for Android

I have memory leaks regarding Interstitial ads of AdMob with AdActivity object. Whenever an ad is shown, AdActivity object count in the memory increments by 1. I inspect all changes via MAT after explicit GC calls. I use the latest versions of everything.
At first, I thought that this is related to how I implemented my UI or project, but creating a fresh and empty project shows the same leak.
This leak has also existed in the previous Admob SDK (Google Play Services) and now it exists in version 7.0 too.
I see that people try to solve these kinds of issues by creating a SingleInstance empty activity just to show and set as the context of the interstitial ads. I tried them all and they did not work for my case. Some did help but I even couldn't use it because of the flow of my app. launchMode in Android has limitations and it does not help me on my case.
I already notified the AdMob team but even they fix it, it doesn't seem to happen in a short time as they have just released the version 7.0 SDK.
I do not understand how others do not report leaks like this. It cannot be a special case just for me as it happens on even samples or default templates. If anyone somehow solved this issue (including ugly reflection hacks) please share your experience. I have been working on this for months! Really!
AndroidManifest:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
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"
android:theme="#android:style/Theme.Translucent" />
</application>
MainActivity:
package com.example.leaktest1;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private InterstitialAd interstitial=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
interstitial= new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId("YOUR-ADD-ID");
AdRequest adRequest2 = new AdRequest.Builder()
// .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
if(interstitial.isLoaded()){
interstitial.show();
}
}
});
interstitial.loadAd(adRequest2);
}
#Override
protected void onDestroy() {
if(interstitial!=null){
interstitial.setAdListener(null);
interstitial=null;
}
super.onDestroy();
}
}
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.example.leaktest1.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Start the app. When the ad is shown, close it with backpress and hit back button again to exit app.
App will still be in memory, but the activity is gone. Now touch the app icon to start the activity again, it will show the ad again, exit like you did before.
Cause GC multiple times and get heap dump. You will see that there are 2 AdActivity objects (and also many other related objects). It will continue to grow according to the number of shown ads.
The following did not work too (it still leaks):
/*
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
}
});*/
interstitial.loadAd(adRequest2);
Runnable r=new Runnable() {
#Override
public void run() {
if(interstitial.isLoaded()){
interstitial.show();
}
}};
new Handler().postDelayed(r,10000);
And putting code inside a button did not work too (it still leaks):
Button b = new Button(this);
b.setText("Touch me");
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(interstitial.isLoaded()){
interstitial.show();
}
}
});
ViewGroup v = (ViewGroup) this.findViewById(android.R.id.content);
v.addView(b);
Leak platform and exceptions:
This leak happens on various devices from Samsung and Asus with various un-modded (original firmware) Androis systems from 2.3 to 4.4. It also happens on any setup of android simulator.
(This leak does not show up on rooted Cyanogenmod (Galaxy S3) Android 4.4.4)
UPDATE
The leak does not vanish if I use Activity context instead of Application context. It also causes Activity leak too.

When dismiss interstitial DFP ad on Android, the app crashes

I have a simple interstitial DFP (DoubleClick for Publishers) ad in my Android app. When I touch the cross to comeback to the app, the app closes itself.
The code is ok because it works in another app. Does anyone have an idea?
Here is the code in the manifest :
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize"/>
In the activity where I want the pub:
...extends Activity implements OnTouchListener, OnClickListener, OnErrorListener, AdListener, OnCompletionListener...
and the pub code:
private DfpInterstitialAd interstitial;
interstitial = new DfpInterstitialAd(this, "THE_PUB_CODE");
AdRequest adRequest = new AdRequest();
interstitial.loadAd(adRequest);
interstitial.setAdListener(this);
I found the solution
There was a finish() in the method onUserLeaveHint()

Phonegap Android application restarting instead of resuming on coming back after home button click

I have created PhoneGap 1.4/ with Android application with plugins.
My client reports that, when he leaves the app using the Home button, and then relaunches it using the app icon, the app relaunches from the start instead of resuming. However, when he press on lock or go to sleep the app resumes in the expected way.
The initialization process of the app is declared this way :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("EMOFIDActivity", "onCreatee " + this.getIntent());
super.loadUrl("file:///android_asset/www/index.html");
}
#Override
public void onPause() {
Log.d("EMOFIDActivity", "onPause " + this.getIntent());
super.onPause();
}// On click of home button this method is getting called
#Override
public void onResume() {
Log.d("EMOFIDActivity", "onResume " + this.getIntent());
super.onResume();
} // On click of app icon application is getting relaunched without coming to this function.
I have included three android Plugins and overridden the onPause() & onResume() methods like this. Here also OnResume() method is not at all getting called.
#Override
public void onPause(boolean multitasking) {
Log.d(TAG, "onPause " + ctx.getIntent());
super.onPause(multitasking);
stopNfc();
}
#Override
public void onResume(boolean multitasking) {
Log.d(TAG, "onResume " + ctx.getIntent());
super.onResume(multitasking);
startNfc();
}
Is there a way to resolve this problem and come back to state where I Paused my application? What could be the problem in this process?
I had the same problem . My app was getting restarted when i click the app icon to relaunch the already running app in the background.
Basically if the
android:launchMode
is set to standard or not set ,then a new intent is created for the app and the old paused state of app is not resumed .
So the best way around i found was to apply
android:launchMode="singleTask"
in the AndroidManifest.xml -> inside .
please conside this example :
<activity android:name="Example" android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Categories

Resources