com.google.ads.mediation.admob.AdMobAdapter Java Examples

The following examples show how to use com.google.ads.mediation.admob.AdMobAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdmobPlus.java    From admob-plus with MIT License 6 votes vote down vote up
private AdRequest.Builder createAdRequestBuilder(PluginCall call) {
    AdRequest.Builder builder = new AdRequest.Builder();

    JSArray testDevices = call.getArray("testDevices", new JSArray());
    for (int i = 0; i < testDevices.length(); i++) {
        try {
            builder.addTestDevice(testDevices.getString(i));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (call.getBoolean("childDirected") != null) {
        builder.tagForChildDirectedTreatment(call.getBoolean("childDirected"));
    }

    Boolean nonPersonalizedAds = call.getBoolean("nonPersonalizedAds");
    if (nonPersonalizedAds != null && nonPersonalizedAds) {
        Bundle extras = new Bundle();
        extras.putString("npa", "1");
        builder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
    }

    return builder;
}
 
Example #2
Source File: Action.java    From admob-plus with MIT License 6 votes vote down vote up
public AdRequest buildAdRequest() {
    Bundle extras = new Bundle();
    AdRequest.Builder builder = new AdRequest.Builder();
    JSONArray testDevices = this.opts.optJSONArray("testDevices");
    if (testDevices != null) {
        for (int i = 0; i < testDevices.length(); i++) {
            String testDevice = testDevices.optString(i);
            if (testDevice != null) {
                builder.addTestDevice(testDevice);
            }
        }
    }
    if (this.opts.has("childDirected")) {
        builder.tagForChildDirectedTreatment(opts.optBoolean("childDirected"));
    }
    if (this.opts.has("npa")) {
        extras.putString("npa", opts.optString("npa"));
    }
    if (this.opts.has("underAgeOfConsent")) {
        extras.putBoolean("tag_for_under_age_of_consent", opts.optBoolean("underAgeOfConsent"));
    }
    return builder.addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
}
 
Example #3
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 6 votes vote down vote up
@Override
protected Object __prepareRewardVideoAd(String adId) {
  // safety check to avoid exceptoin in case adId is null or empty
  if(adId==null || adId.length()==0) adId = TEST_REWARDVIDEO_ID;

  RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(getActivity());
  ad.setRewardedVideoAdListener(new RewardVideoListener());

  synchronized (mLock) {
    if (!mIsRewardedVideoLoading) {
      mIsRewardedVideoLoading = true;
      Bundle extras = new Bundle();
      extras.putBoolean("_noRefresh", true);
      AdRequest adRequest = new AdRequest.Builder()
              .addNetworkExtrasBundle(AdMobAdapter.class, extras)
              .build();
      ad.loadAd(adId, adRequest);
    }
  }

  return ad;
}
 
Example #4
Source File: Game.java    From FlappyCow with MIT License 6 votes vote down vote up
private void setupAd() {
    MobileAds.initialize(this, getResources().getString(R.string.ad_app_id));

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(getResources().getString(R.string.ad_unit_id));

    Bundle extras = new Bundle();
    // Make sure only adds appropriate for children of all ages are displayed.
    extras.putString("max_ad_content_rating", "G");

    AdRequest adRequest = new AdRequest.Builder()
            .addNetworkExtrasBundle(AdMobAdapter.class, extras)
            .build();

    interstitial.loadAd(adRequest);
    interstitial.setAdListener(new MyAdListener());
}
 
Example #5
Source File: ConsentSDK.java    From GDPR-Admob-Android with MIT License 5 votes vote down vote up
public static AdRequest getAdRequest(Context context) {
    if(isConsentPersonalized(context)) {
        return new AdRequest.Builder().build();
    } else {
        return new AdRequest.Builder()
                .addNetworkExtrasBundle(AdMobAdapter.class, getNonPersonalizedAdsBundle())
                .build();
    }
}
 
Example #6
Source File: MainGameActivity.java    From Trivia-Knowledge with Apache License 2.0 5 votes vote down vote up
public void loadAdRewardedVideo() {
    if (!mAd.isLoaded()) {

        Bundle extras = new Bundle();
        extras.putBoolean("_noRefresh", true);
        AdRequest adRequest = new AdRequest.Builder()
                .addNetworkExtrasBundle(AdMobAdapter.class, extras)
                //.addNetworkExtrasBundle(ChartboostAdapter.class, extras)
                .addNetworkExtrasBundle(UnityAdapter.class, extras)
                .build();
        mAd.loadAd(getString(R.string.Test_admob_unit_id_rewardedVideo), adRequest);
        // Toast.makeText(MainGameActivity.this,"called",Toast.LENGTH_LONG).show();
    }
}
 
Example #7
Source File: AdMob.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static AdRequest makeAdRequest() {
    if (EuConsent.getConsentLevel() < EuConsent.PERSONALIZED) {
        Bundle extras = new Bundle();
        extras.putString("npa", "1");

        return new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
    }

    return new AdRequest.Builder().build();
}
 
Example #8
Source File: GooglePlayServicesBanner.java    From mobile-sdk-android with Apache License 2.0 5 votes vote down vote up
public static AdRequest buildRequest(TargetingParameters targetingParameters) {
    AdRequest.Builder builder = new AdRequest.Builder();

    if (targetingParameters != null) {
        if (targetingParameters.getLocation() != null) {
            builder.setLocation(targetingParameters.getLocation());
        }
        Bundle bundle = new Bundle();

        if (targetingParameters.getAge() != null) {
            bundle.putString("Age", targetingParameters.getAge());
        }

        for (Pair<String, String> p : targetingParameters.getCustomKeywords()) {
            if (p.first.equals("content_url")) {
                if (!StringUtil.isEmpty(p.second)) {
                    builder.setContentUrl(p.second);
                }
            } else {
                bundle.putString(p.first, p.second);
            }
        }

        builder.addNetworkExtrasBundle(AdMobAdapter.class, bundle);
    }


    return builder.build();
}
 
Example #9
Source File: AdMob.java    From cordova-plugin-admob-free with MIT License 4 votes vote down vote up
public AdRequest buildAdRequest() {
    AdRequest.Builder builder = new AdRequest.Builder();
    if (config.isTesting || isRunningInTestLab()) {
        builder = builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).addTestDevice(getDeviceId());
    }

    if (config.testDeviceList != null) {
        Iterator<String> iterator = config.testDeviceList.iterator();
        while (iterator.hasNext()) {
            builder = builder.addTestDevice(iterator.next());
        }
    }

    Bundle bundle = new Bundle();
    bundle.putInt("cordova", 1);
    if (config.adExtras != null) {
        Iterator<String> it = config.adExtras.keys();
        while (it.hasNext()) {
            String key = it.next();
            try {
                bundle.putString(key, config.adExtras.get(key).toString());
            } catch (JSONException exception) {
                Log.w(TAG, String.format("Caught JSON Exception: %s", exception.getMessage()));
            }
        }
    }
    builder = builder.addNetworkExtrasBundle(AdMobAdapter.class, bundle);

    if (config.gender != null) {
        if ("male".compareToIgnoreCase(config.gender) != 0) {
            builder.setGender(AdRequest.GENDER_MALE);
        } else if ("female".compareToIgnoreCase(config.gender) != 0) {
            builder.setGender(AdRequest.GENDER_FEMALE);
        } else {
            builder.setGender(AdRequest.GENDER_UNKNOWN);
        }
    }
    if (config.location != null) {
        builder.setLocation(config.location);
    }
    if ("yes".equals(config.forFamily)) {
        builder.setIsDesignedForFamilies(true);
    } else if ("no".equals(config.forFamily)) {
        builder.setIsDesignedForFamilies(false);
    }
    if ("yes".equals(config.forChild)) {
        builder.tagForChildDirectedTreatment(true);
    } else if ("no".equals(config.forChild)) {
        builder.tagForChildDirectedTreatment(false);
    }
    if (config.contentURL != null) {
        builder.setContentUrl(config.contentURL);
    }

    return builder.build();
}