android – Admob interstitial with audio-ThrowExceptions

Exception or error:

I hope someone can give information about this.
I display interstitial ads with Admob. Some of them have music or sounds and my users get terrible annoyed because of this. So, does anyone know if there is a way to block ads with music or sound? Is there anyway to decline access to the loud speaker for the ads?
Thanks

How to solve:

I had the same issue. I was shocked to hear some audio in background too. This is what I did.
Mute the sound before showing the ad.
Unmute the sound onAdClosed() of AdListener. You can set the adListener on the interstitial ad while loading the ad.

private InterstitialAd interstitialAd;
private void showTheAd(){
    _muteSound();
    interstitialAd.show();
}


private void loadAd(){
    interstitialAd = new InterstitialAd(context);
    interstitialAd.setAdUnitId("ca-app-pub-XXXXXXx/XXXXXXXX");
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(
            AdRequest.DEVICE_ID_EMULATOR).build();
    interstitialAd.loadAd(adRequest);
    interstitialAd.setAdListener(new AdListener() {
            public void onAdClosed(){
                _unmuteSound();
            }
        });
}

private void _unmuteSound(){
    AudioManager aManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
                aManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
private void _muteSound(){
    AudioManager aManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
                aManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
}

###

to mute an ad, just call MobileAds.setAppmuted(true)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    // Set app volume to be half of current device volume.
    MobileAds.setAppVolume(0.5f); // or setAppMuted(true); to mute 
    ...
}

from their forum page: https://groups.google.com/forum/#!topic/google-admob-ads-sdk/X7hQeehlJBI

The Google Mobile Ads SDK for Android has methods to set the current volume for incoming ads, based on the device’s current volume level.

setAppVolume(float) – available in the Android AdMob SDK version 8.4
and up. setAppMuted(boolean) – available in the Android AdMob SDK version 9.0 and up.

for further readings, refer to https://developers.google.com/admob/android/global-settings and https://developers.google.com/android/reference/com/google/android/gms/ads/MobileAds

###

Well you can log-on to your AdMob account and go to your app and then choose to edit your interstitial ad-unit link in the table that displays the ad-units for this app.

In there, you’ll see 3 Ad types as check-box options – Text, Image and Video. Uncheck the Video option and save your settings.

You’ve now solved successfully the problem of showing loud audio/video ads that nag your users. Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *