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()
Related
In onAdDismissedFullScreenContent of Interstitial Ad start new Activity using startActiviy(Intent(...)) in normal case ad show and close the inter ad the new Activity start normally.
The issue is when Inter Ad show then I press home button and open app again from recents then I press on inter ad close the Ad close but the new Activity start after few seconds why.
here is onAdDismissedFullScreenContent code
override fun onAdDismissedFullScreenContent() {
startActivity(new Intent(this, NewActivity.class));
finish()
}
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();
}
});
}
});
My app just keeps crashing after I tryed to use banner ads with AdMob (without it everything works just fine). The SplashScreen loads but the app crashes when the game should start. Here are the steps that I followed to implemet this:
1) I made sure that I have installed Google Play Services and Google Repository
2) Then I connected my app to Firebase using Firebase Tool Assistant ( it just added google services.json under the app folder in my project )
3)Then I added the AdMob to my app, as shown here:
4)I added this codes in my layout:
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
5)In my Main Activity class called "Game" I added this code to onCreate() method as you can see here:
public class Game extends Activity {
//ADMOB
private AdView mAdView;
MediaPlayer sound;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn title off
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new GamePanel(this));
//ADMOB
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
int[] sounds={R.raw.chiptune, R.raw.chiptune1, R.raw.chiptune2, R.raw.chiptune3};
Random r = new Random();
int Low = 0;
int High = 4;
int rand = r.nextInt(High-Low) + Low;
sound = MediaPlayer.create(getApplicationContext(),sounds[rand]);
sound.start();
sound.setLooping(true);
}
6) Add this to my strings: <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
7) In my AndroidManifest.xml I added this pieces of codes:
<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--This meta-data tag is required to use Google Play services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
I wounder what's wrong, if anybody can help!
Here is the Crash Log:
findViewById(R.id.adView); returns a View if it exists in the layout you provided in setContentView(), otherwise it returns null and that's what happening to you.
mAdView is null so you're getting null pointer exception.
So create a layout.xml, embed GamePanel view and AdView both then pass that layout to setContentView(); method.
I am having a strange problem with Adview. I was checking my android code on device and when I clicked on Adview banner, I got "Complete Action using" dialog box. But now, when I tried to open the app again, it got struck at "complete action using" dialog box.
I searched stackoverflow for last 1 hour but did not find any answer.
Below is the onCreate() of my Main activity
AdView adView = (AdView) findViewById(R.id.ads_text);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
And the Manifest for Adview is
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent">
</activity>
Hope to see a quick answer soon. Thnaks!
You didn't mention what options were in your "Complete Action using" dialog, but I suspect it will be a couple of web browsers.
This is entirely normal. When an app provides an Action Intent to the Android framework for actioning, if the Android framework has more than one app that could complete the Action (and no default has yet been selected) then it prompts the user for which app to use.
It sounds like you have installed an app that has declared that it can respond to View URL Intents. SO you are getting that app along with your std browser being offered as consumers.
Nothing to see here. Move along.
I noticed I get the following messages after the screen has been off:
I/Ads﹕ Ad is not visible. Not refreshing ad.
I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
I have the following code inside onResume:
if (adView != null) {
adView.resume();
}
I stepped the code and it does get called just fine. It also works just fine if I get out of the activity and back in, the only issue appears to be when coming back after the screen goes off.
Anyone else with this issue?
Thanks.
EDIT: The code I use to create the adview and request
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(id);
LinearLayout layout = (LinearLayout) findViewById(R.id.main_layout);
layout.addView(adView);
createAdRequest();
The code of createAdRequest():
AdRequest.Builder builder = new AdRequest.Builder();
builder.addKeyword(somekeyword);
AdRequest adRequest = builder.build();
adView.loadAd(adRequest);
I have noticed something else that is odd, I sometimes call createAdRequest again if I notice the keyword has changed, after I make that call the ads seem to stop refreshing as well but this time I don't see any visibility messages, I just don't see anymore requests until I call createAdRequest again.
Did you add code to your onPause and onDestroy as well?
#Override
protected void onPause() {
adView.pause();
super.onPause();
}
#Override
protected void onResume() {
super.onResume();
adView.resume();
}
Ok. I am nothing if not persistent. I tested with this and as a caveat I have been using these flags the whole time. I haven't removed the flags but now with this broadcast receiver it works properly and seems to isolate the issue even more. I will explain.
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON | // In onCreate
LayoutParams.FLAG_DISMISS_KEYGUARD |
LayoutParams.FLAG_SHOW_WHEN_LOCKED |
LayoutParams.FLAG_TURN_SCREEN_ON);
First of all I already had the receiver for another purpose. And as you can see my flags turn my screen back on but I also have a mechanism that will start the activity for me if needed(Which will need to be tweaked now because of this bug). So the fact that this works as is with all of my other mentioned mechanisms seems to imply a timing issue where AdView checks for the screens status once then doesn't check after it is back on. This was my original suspicion but as you can see the onRecieve method returns void so I can't take responsibility. Not sure if I can completely blame the Author of AdView either since I have seen some weird behavior from this intent before. It might even be a problem with the Activitys' ability to handle the intent too.
Anyway sorry if I am rambling the take away here is that I implemented the receiver to finish the activity when the screen is turned off. And I don't personally worry about starting it back up but if you need to then I added a comment to the code for that too.
[Edit] I will make this a little clearer for the most likely scenario of the Activity context. I was using a Service so that is why mine looked different. I haven't tested this one but it should work the same except I am not sure how you would check if the activity can be finished. Not even sure if that matters. My tested working code will be in my edits though if you need them as a reference.
[Edit] I did end up using this in the Activity context and it worked as expected. If the KeyGuard is not secure. Read comments for full story.
class MyActivity extends Activity {
ScreenReceiver receiver;
#Override
protected void onCreate(Bundle savedInstance){
receiver = new ScreenReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(receiver, filter);
}
#Override
protected void onDestroy(){
unregisterReceiver(receiver);
}
private class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i(getClass().getSimpleName(), "Got " + intent.getAction());
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
MyActivity.this.finish();
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// context.startActivity(new Intent(context, MyActivity.class));
}
}
}
}
I had this problem. In my case the size of the banner (adSize) was greater than the available screen area. Make sure you do not have conflicting layouts.
Admob will not refresh unless the ad is visible to user. Obviously when your phone turns off no one can see ads, thus there is no reason for Admob to request another ad.
I personally faced the same problem a couple of times. Once I was placing AdView bellow a ListView. The AdView was not visible until the list was scrolled to the bottom, therefore Admob was constantly logging "Ad is not visible. Not refreshing ad."
Another time, I had no internet connection and the same message was continuously being logged.
I am going to try this approach I think it will pay off. I have been troubleshooting this all day. I should hope that I have a good grasp on it by now. I pasted the relevant part of the post the has the approach. Of course the onResume should be infered. For instance I am going to simply move the ad creation from the onCreate method. If you were using xml to define your ad obviously you would need to change to strictly code.
https://groups.google.com/forum/#!topic/google-admob-ads-sdk/jz-ZQh86lm0
The only way I could have the log stay silent was to remove the entire ad in onPause and add it again in onResume.
If I added the below lines everything works fine, but since this is not the recommended approach then it would be great if the timer was stopped when calling onPause.
admobAdView.pause();
((LinearLayout)admobAdView.getParent()).removeView(admobAdView);
admobAdView.destroy();
admobAdView = null;