Search in sources :

Example 11 with AdRequest

use of com.google.android.gms.ads.AdRequest in project mopub-android-mediation by mopub.

the class GooglePlayServicesRewardedVideo method load.

@Override
protected void load(@NonNull final Context context, @NonNull final AdData adData) {
    Preconditions.checkNotNull(context);
    Preconditions.checkNotNull(adData);
    setAutomaticImpressionAndClickTracking(false);
    mContext = context;
    final Map<String, String> extras = adData.getExtras();
    mAdUnitId = extras.get(KEY_EXTRA_AD_UNIT_ID);
    if (TextUtils.isEmpty(mAdUnitId)) {
        MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR.getIntCode(), MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
        if (mLoadListener != null) {
            mLoadListener.onAdLoadFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
        }
        return;
    }
    if (!(context instanceof Activity)) {
        MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Context passed to load " + "was not an Activity.");
        if (mLoadListener != null) {
            mLoadListener.onAdLoadFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
        }
        return;
    }
    final AdRequest.Builder builder = new AdRequest.Builder();
    builder.setRequestAgent("MoPub");
    // Publishers may append a content URL by passing it to the
    // GooglePlayServicesMediationSettings instance when initializing the MoPub SDK:
    // https://developers.mopub.com/docs/mediation/networks/google/#android
    String contentUrl = extras.get(KEY_CONTENT_URL);
    if (TextUtils.isEmpty(contentUrl)) {
        contentUrl = GooglePlayServicesMediationSettings.getContentUrl();
    }
    if (!TextUtils.isEmpty(contentUrl)) {
        builder.setContentUrl(contentUrl);
    }
    forwardNpaIfSet(builder);
    final RequestConfiguration.Builder requestConfigurationBuilder = new RequestConfiguration.Builder();
    // Publishers may request for test ads by passing test device IDs to the
    // GooglePlayServicesMediationSettings instance when initializing the MoPub SDK:
    // https://developers.mopub.com/docs/mediation/networks/google/#android
    String testDeviceId = extras.get(TEST_DEVICES_KEY);
    if (TextUtils.isEmpty(testDeviceId)) {
        testDeviceId = GooglePlayServicesMediationSettings.getTestDeviceId();
    }
    if (!TextUtils.isEmpty(testDeviceId)) {
        requestConfigurationBuilder.setTestDeviceIds(Collections.singletonList(testDeviceId));
    }
    // Publishers may want to indicate that their content is child-directed and
    // forward this information to Google.
    final String isTFCDString = extras.get(TAG_FOR_CHILD_DIRECTED_KEY);
    final Boolean isTFCD;
    if (!TextUtils.isEmpty(isTFCDString)) {
        isTFCD = Boolean.valueOf(isTFCDString);
    } else {
        isTFCD = GooglePlayServicesMediationSettings.isTaggedForChildDirectedTreatment();
    }
    if (isTFCD != null) {
        if (isTFCD) {
            requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);
        } else {
            requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);
        }
    } else {
        requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);
    }
    // Publishers may want to mark their requests to receive treatment for users
    // in the European Economic Area (EEA) under the age of consent.
    final String isTFUAString = extras.get(TAG_FOR_UNDER_AGE_OF_CONSENT_KEY);
    final Boolean isTFUA;
    if (!TextUtils.isEmpty(isTFUAString)) {
        isTFUA = Boolean.valueOf(isTFUAString);
    } else {
        isTFUA = GooglePlayServicesMediationSettings.isTaggedForUnderAgeOfConsent();
    }
    if (isTFUA != null) {
        if (isTFUA) {
            requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);
        } else {
            requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);
        }
    } else {
        requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);
    }
    final RequestConfiguration requestConfiguration = requestConfigurationBuilder.build();
    MobileAds.setRequestConfiguration(requestConfiguration);
    final AdRequest adRequest = builder.build();
    RewardedAd.load(context, mAdUnitId, adRequest, new RewardedAdLoadCallback() {

        @Override
        public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
            Preconditions.checkNotNull(rewardedAd);
            if (mLoadListener != null) {
                mLoadListener.onAdLoaded();
            }
            MoPubLog.log(getAdNetworkId(), LOAD_SUCCESS, ADAPTER_NAME);
            mRewardedAd = rewardedAd;
            mRewardedAd.setFullScreenContentCallback(new FullScreenContentCallback() {

                @Override
                public void onAdImpression() {
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdImpression();
                    }
                }

                @Override
                public void onAdShowedFullScreenContent() {
                    MoPubLog.log(getAdNetworkId(), SHOW_SUCCESS, ADAPTER_NAME);
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdShown();
                    }
                }

                @Override
                public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
                    Preconditions.checkNotNull(adError);
                    MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to show " + "Google rewarded video. " + adError.getMessage());
                    MoPubLog.log(getAdNetworkId(), SHOW_FAILED, ADAPTER_NAME, MoPubErrorCode.FULLSCREEN_SHOW_ERROR.getIntCode(), MoPubErrorCode.FULLSCREEN_SHOW_ERROR);
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdFailed(MoPubErrorCode.FULLSCREEN_SHOW_ERROR);
                    }
                    mRewardedAd = null;
                }

                @Override
                public void onAdDismissedFullScreenContent() {
                    MoPubLog.log(getAdNetworkId(), DID_DISAPPEAR, ADAPTER_NAME);
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdDismissed();
                    }
                    mRewardedAd = null;
                }
            });
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            Preconditions.checkNotNull(loadAdError);
            MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to load " + "Google rewarded video. " + loadAdError.getMessage());
            MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR.getIntCode(), MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
            MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to load Google " + "interstitial with message: " + loadAdError.getMessage() + ". Caused by: " + loadAdError.getCause());
            if (mLoadListener != null) {
                mLoadListener.onAdLoadFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
            }
            mRewardedAd = null;
        }
    });
    MoPubLog.log(getAdNetworkId(), LOAD_ATTEMPTED, ADAPTER_NAME);
}
Also used : RequestConfiguration(com.google.android.gms.ads.RequestConfiguration) LoadAdError(com.google.android.gms.ads.LoadAdError) Activity(android.app.Activity) RewardedAdLoadCallback(com.google.android.gms.ads.rewarded.RewardedAdLoadCallback) AdRequest(com.google.android.gms.ads.AdRequest) RewardedAd(com.google.android.gms.ads.rewarded.RewardedAd) FullScreenContentCallback(com.google.android.gms.ads.FullScreenContentCallback) NonNull(androidx.annotation.NonNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoadAdError(com.google.android.gms.ads.LoadAdError) AdError(com.google.android.gms.ads.AdError)

Example 12 with AdRequest

use of com.google.android.gms.ads.AdRequest in project mopub-android-mediation by mopub.

the class GooglePlayServicesInterstitial method load.

@Override
protected void load(@NonNull final Context context, @NonNull final AdData adData) {
    Preconditions.checkNotNull(context);
    Preconditions.checkNotNull(adData);
    mContext = context;
    setAutomaticImpressionAndClickTracking(false);
    final Map<String, String> extras = adData.getExtras();
    if (extrasAreValid(extras)) {
        mAdUnitId = extras.get(AD_UNIT_ID_KEY);
        mGooglePlayServicesAdapterConfiguration.setCachedInitializationParameters(context, extras);
    } else {
        MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, MoPubErrorCode.NETWORK_NO_FILL.getIntCode(), MoPubErrorCode.NETWORK_NO_FILL);
        if (mLoadListener != null) {
            mLoadListener.onAdLoadFailed(MoPubErrorCode.NETWORK_NO_FILL);
        }
        return;
    }
    final AdRequest.Builder builder = new AdRequest.Builder();
    builder.setRequestAgent("MoPub");
    // Publishers may append a content URL by passing it to the MoPubInterstitial.setLocalExtras() call.
    final String contentUrl = extras.get(CONTENT_URL_KEY);
    if (!TextUtils.isEmpty(contentUrl)) {
        builder.setContentUrl(contentUrl);
    }
    forwardNpaIfSet(builder);
    final RequestConfiguration.Builder requestConfigurationBuilder = new RequestConfiguration.Builder();
    // Publishers may request for test ads by passing test device IDs to the MoPubView.setLocalExtras() call.
    final String testDeviceId = extras.get(TEST_DEVICES_KEY);
    if (!TextUtils.isEmpty(testDeviceId)) {
        requestConfigurationBuilder.setTestDeviceIds(Collections.singletonList(testDeviceId));
    }
    // Publishers may want to indicate that their content is child-directed and forward this
    // information to Google.
    final String childDirected = extras.get(TAG_FOR_CHILD_DIRECTED_KEY);
    if (childDirected != null) {
        if (Boolean.parseBoolean(childDirected)) {
            requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);
        } else {
            requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);
        }
    } else {
        requestConfigurationBuilder.setTagForChildDirectedTreatment(TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);
    }
    // Publishers may want to mark their requests to receive treatment for users in the
    // European Economic Area (EEA) under the age of consent.
    final String underAgeOfConsent = extras.get(TAG_FOR_UNDER_AGE_OF_CONSENT_KEY);
    if (underAgeOfConsent != null) {
        if (Boolean.parseBoolean(underAgeOfConsent)) {
            requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);
        } else {
            requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);
        }
    } else {
        requestConfigurationBuilder.setTagForUnderAgeOfConsent(TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);
    }
    final RequestConfiguration requestConfiguration = requestConfigurationBuilder.build();
    MobileAds.setRequestConfiguration(requestConfiguration);
    final AdRequest adRequest = builder.build();
    InterstitialAd.load(context, mAdUnitId, adRequest, new InterstitialAdLoadCallback() {

        @Override
        public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
            Preconditions.checkNotNull(interstitialAd);
            mGoogleInterstitialAd = interstitialAd;
            MoPubLog.log(getAdNetworkId(), LOAD_SUCCESS, ADAPTER_NAME);
            if (mLoadListener != null) {
                mLoadListener.onAdLoaded();
            }
            mGoogleInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {

                @Override
                public void onAdDismissedFullScreenContent() {
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdDismissed();
                    }
                    mGoogleInterstitialAd = null;
                }

                @Override
                public void onAdFailedToShowFullScreenContent(@NonNull AdError adError) {
                    Preconditions.checkNotNull(adError);
                    MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to show " + "Google interstitial. " + adError.getMessage());
                    MoPubLog.log(getAdNetworkId(), SHOW_FAILED, ADAPTER_NAME, MoPubErrorCode.NETWORK_NO_FILL.getIntCode(), MoPubErrorCode.NETWORK_NO_FILL);
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdFailed(MoPubErrorCode.NETWORK_NO_FILL);
                    }
                    mGoogleInterstitialAd = null;
                }

                @Override
                public void onAdShowedFullScreenContent() {
                    MoPubLog.log(getAdNetworkId(), SHOW_SUCCESS, ADAPTER_NAME);
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdShown();
                    }
                }

                @Override
                public void onAdImpression() {
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdImpression();
                    }
                }
            });
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            Preconditions.checkNotNull(loadAdError);
            MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR.getIntCode(), MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
            MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to load Google " + "interstitial. " + loadAdError.getMessage());
            if (mLoadListener != null) {
                mLoadListener.onAdLoadFailed(MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR);
            }
        }
    });
    MoPubLog.log(getAdNetworkId(), LOAD_ATTEMPTED, ADAPTER_NAME);
}
Also used : RequestConfiguration(com.google.android.gms.ads.RequestConfiguration) LoadAdError(com.google.android.gms.ads.LoadAdError) AdRequest(com.google.android.gms.ads.AdRequest) FullScreenContentCallback(com.google.android.gms.ads.FullScreenContentCallback) NonNull(androidx.annotation.NonNull) InterstitialAdLoadCallback(com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback) InterstitialAd(com.google.android.gms.ads.interstitial.InterstitialAd) LoadAdError(com.google.android.gms.ads.LoadAdError) AdError(com.google.android.gms.ads.AdError)

Example 13 with AdRequest

use of com.google.android.gms.ads.AdRequest in project scroball by peterjosling.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    application = (ScroballApplication) getApplication();
    application.startListenerService();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    TabLayout tabLayout = findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Initial tab may have been specified in the intent.
    int initialTab = getIntent().getIntExtra(EXTRA_INITIAL_TAB, TAB_NOW_PLAYING);
    mViewPager.setCurrentItem(initialTab);
    this.adsRemoved = application.getSharedPreferences().getBoolean(REMOVE_ADS_SKU, false);
    adView = findViewById(R.id.adView);
    if (this.adsRemoved) {
        RelativeLayout parent = (RelativeLayout) adView.getParent();
        if (parent != null) {
            parent.removeView(adView);
        }
    } else {
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("86193DC9EBC8E1C3873178900C9FCCFC").build();
        adView.loadAd(adRequest);
    }
}
Also used : AdRequest(com.google.android.gms.ads.AdRequest) TabLayout(com.google.android.material.tabs.TabLayout) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar)

Example 14 with AdRequest

use of com.google.android.gms.ads.AdRequest in project Space-Station-Tracker by Kiarasht.

the class MapsActivity method requestNewInterstitial.

/**
     * Request for a new interstitial ad
     */
private void requestNewInterstitial() {
    if (!mSharedPreferences.getBoolean("fullPage", false)) {
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
        mInterstitialAd.loadAd(adRequest);
    }
}
Also used : AdRequest(com.google.android.gms.ads.AdRequest)

Example 15 with AdRequest

use of com.google.android.gms.ads.AdRequest in project Space-Station-Tracker by Kiarasht.

the class MapsActivity method initializeAds.

/**
     * Initialize ads when the activity is started for the first time
     */
private void initializeAds() {
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    MobileAds.initialize(mContext, getString(R.string.app_ID_Main));
    // Initiate the interstitial ad and onAdClosed listener
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
    mInterstitialAd.setAdListener(new AdListener() {

        @Override
        public void onAdClosed() {
            requestNewInterstitial();
            switch(mInterstitialAdActivity) {
                case 0:
                    startActivity(new Intent(mContext, Locations.class));
                    break;
                case 1:
                    startActivity(new Intent(mContext, PeopleinSpace.class));
                    break;
            }
        }
    });
    if (!mSharedPreferences.getBoolean("advertisement", false)) {
        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
        mAdView.loadAd(adRequest);
    } else if (mAdView == null) {
        findViewById(R.id.adView).setVisibility(View.GONE);
    }
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) AdRequest(com.google.android.gms.ads.AdRequest) InterstitialAd(com.google.android.gms.ads.InterstitialAd) Intent(android.content.Intent) AdListener(com.google.android.gms.ads.AdListener)

Aggregations

AdRequest (com.google.android.gms.ads.AdRequest)24 AdView (com.google.android.gms.ads.AdView)11 SharedPreferences (android.content.SharedPreferences)5 View (android.view.View)4 AdListener (com.google.android.gms.ads.AdListener)4 InterstitialAd (com.google.android.gms.ads.InterstitialAd)4 NavigationView (android.support.design.widget.NavigationView)3 AdSize (com.google.android.gms.ads.AdSize)3 FullScreenContentCallback (com.google.android.gms.ads.FullScreenContentCallback)3 LoadAdError (com.google.android.gms.ads.LoadAdError)3 RequestConfiguration (com.google.android.gms.ads.RequestConfiguration)3 PoolDbHelper (it.angelic.mpw.model.db.PoolDbHelper)3 Toolbar (android.support.v7.widget.Toolbar)2 ViewTreeObserver (android.view.ViewTreeObserver)2 Button (android.widget.Button)2 RadioGroup (android.widget.RadioGroup)2 RelativeLayout (android.widget.RelativeLayout)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 AdError (com.google.android.gms.ads.AdError)2