I just made game like ironpants, I'm trying to put interstitial ads when the game over.
but the interstitial ads always show in the middle of the game. I think it'll be annoying for users. and I'm afraid if Google will banned my admob account.
The interstitial ads only show after 5x game over.
I only have onescreen MainGameView.java
here's the code to show admob interstitial ads when the game was over
the methods to initialize the interstitial ads
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialiseAccelerometer();
// Create the interstitial
interstitial = new InterstitialAd(this, getResources().getString(R.string.InterstitialAd_unit_id));
}
public void openAd() {
runOnUiThread(new Runnable() {
public void run() {
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(new AdListener() {
#Override
public void onReceiveAd(Ad arg0) {
if (interstitial.isReady()) {
interstitial.show();
}
}
#Override
public void onPresentScreen(Ad arg0) {
}
#Override
public void onLeaveApplication(Ad arg0) {
}
#Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
}
#Override
public void onDismissScreen(Ad arg0) {
}
});
}
});
}
and I call openAd() method when the game was over
public synchronized void GameOver() {
if (adounter >= this.getResources().getInteger(R.integer.add_shows_every_X_gameovers)) {
openAd();
adounter = 0;
}
adounter++;
}
thank you very much and sorry for my bad English.
Your problem is that you are showing the interstitial d as soon as it is received (ie in AdListener#onReceiveAd). Don't do this. It provides a poor user experience and will ensure you get low ratings.
Instead show your add at a natural break in your app.
Instead show your add at a natural break in your app.
Exactly, to be more precise it would be good user experience if you do the following:
- request for the ad in onCreate
- in GameOver call:
if (interstitial.isReady()) {
interstitial.show();
}
Related
I see a lot of android app show AdMob interstitial ads without audio that users can unmute than by clicking a speaker button in the ad.
Are all those interstitials muted by default?
Or Do I have to use this method for that AdMob Global Settings
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
//To inform the SDK that the app volume has been muted, use the setAppMuted() method:
MobileAds.setAppMuted(true);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
// 0.5 is the least you can reduce
MobileAds.setAppVolume(0.5);
Set it up
I'm using an admob rewardedAd and everything works fine but sometimes it doesn't show a video. Sometimes it shows a static ad like if it was an intersitial ad. It wouldn't be a problem, but when that happens and the user closes the app, onUserEarnedReward is not fired. Is there a way to force it to always show a rewarded video ad?
Here's the code where I load and prepare the callbacks for the ad:
rewardedAd = new RewardedAd(this, rewardKey);
RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() {
#Override
public void onRewardedAdLoaded() { }
#Override
public void onRewardedAdFailedToLoad(int errorCode) {
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), this);
}
};
adCallback = new RewardedAdCallback() {
#Override
public void onRewardedAdOpened() { }
#Override
public void onRewardedAdClosed() {
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
}
#Override
public void onUserEarnedReward(#NonNull RewardItem reward) {
/*
...
Give rewards to the user
...
*/
rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
}
#Override
public void onRewardedAdFailedToShow(int errorCode) {
Toast.makeText(getApplicationContext(), getString(R.string.ad_error), Toast.LENGTH_LONG).show();
}
};
rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback);
Then I show it like:
rewardedAd.show(this, adCallback);
from your post it seems the issue does not happen all of the time. try not creating so many new instances of rewardedAd from this code you are calling it three times one should be enough rewardedAd = new RewardedAd(getApplicationContext(), rewardKey);
According to the the documentation there is no such thing as a static rewarded ad:
AdMob rewarded ads may be click-to-download video ads with an end
card that appears when the video ends or interactive ads, such as
playable ads or surveys.
Are you sure it's not showing an interactive ad such as a survey, where the user must answer a question to get the reward?
I've added the Admob ad to our Android app. I'm getting Advertising from Android Studio. I receive ads when I manually install the APK file to the phone. However, I can't get ads when I upload the app to Google Play and download it from Google Play. I get error code 3 (ERROR_CODE_NO_FILL). I couldn't find the solution. PLEASE HELP !
android studio avd run img:
img1
when I manually install the APK file to the phone:
img2
When I download it from Google Play:
img3
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadAdmobBanner();
AdmobBannerListener();
}
private void loadAdmobBanner() {
MobileAds.initialize(this, getString(R.string.admob_app_id));
mAdView_Banner = findViewById(R.id.adView_Banner_Main);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView_Banner.loadAd(adRequest);
}
private void AdmobBannerListener(){
mAdView_Banner.setAdListener(new AdListener(){
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
Toast.makeText(MainActivity.this, String.valueOf(i), Toast.LENGTH_SHORT).show();
}
#Override
public void onAdClosed() {
super.onAdClosed();
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
super.onAdOpened();
}
#Override
public void onAdLoaded() {
super.onAdLoaded();
}
#Override
public void onAdClicked() {
super.onAdClicked();
}
#Override
public void onAdImpression() {
super.onAdImpression();
}
});
}
Please go to admobs account. > Go to app > ad units> check if add units are active and are associated with advertiser.
Usually adMob will take time to do this job.
I have received admob policy violation email
LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:
Interstitial ads that load unexpectedly while a user is viewing the app’s content.
Below is my implementation. Please let me know if there is anything wrong with this
private void initShareInterstitial() {
shareInterstitialAd = new InterstitialAd(this);
shareInterstitialAd.setAdUnitId(getString(R.string.share_int));
shareInterstitialAd.loadAd(new AdRequest.Builder().build());
shareInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
// Load the next interstitial.
shareInterstitialAd.loadAd(new AdRequest.Builder().build());
new ShareTask().execute();
}
#Override
public void onAdFailedToLoad(int i) {
shareInterstitialAd.loadAd(new AdRequest.Builder().build());
}
#Override
public void onAdLeftApplication() {
shareInterstitialAd.loadAd(new AdRequest.Builder().build());
}
});
}
in OnCreate Method I am using this code on share button onclick action
if (shareInterstitialAd.isLoaded()
&& random.nextBoolean()
&& random.nextBoolean()) {
shareInterstitialAd.show();
} else {
new ShareTask().execute();
}
Your post codes are not enough to describe the flow to show interstitial ads.
From the limited codes, it is possible that you show App's contents first, then interstitial to overlap the contents. That violates Admob policy. The interstitial has to be shown before the content displayed.
You can refer to their disallowed examples.
Disallowed interstitial implementations
I use Startapp as my ad network in my applications and I need to be able to handle when a user clicks on an ad. I could not find any documentation for this function, and I would rather use onPause() because other things might pause the activity. Help would be appreciated!
Try this:
YourStartAppAd.showAd(new AdDisplayListener() {
#Override
public void adHidden(Ad ad) {
}
#Override
public void adDisplayed(Ad ad) {
}
#Override
public void adClicked(Ad ad) {
}
});
https://github.com/StartApp-SDK/Documentation/wiki/android-advanced-usage