/** * 広告の表示 * * @param dtoMap */ protected void showAdView(Map dtoMap) { try { AdView adView = new AdView(this, AdSize.BANNER, getResources().getString(R.string.mediation_id)); // レイアウトに配置。レイアウトには android:id="@+id/admob" の属性。 LinearLayout layout = (LinearLayout) findViewById(R.id.ad); layout.removeAllViews(); layout.addView(adView); final String CUSTOM_EVENT_LABEL = "MyCustomEventLabel"; // 広告をリクエストする。エミュレータとテスト端末ではテストモードを使用する。 AdRequest adRequest = new AdRequest(); CustomEventExtras extras = new CustomEventExtras(); extras.addExtra("Map", dtoMap); extras.addExtra(CUSTOM_EVENT_LABEL, "hello custom event"); adRequest.setNetworkExtras(extras); Set<String> keywords = new HashSet<String>(); keywords.add(String.valueOf(dtoMap.adType)); keywords.add(dtoMap.adCode01); keywords.add(dtoMap.adCode02); adRequest.addKeywords(keywords); adView.loadAd(adRequest); } catch (Exception e) { e.printStackTrace(); } }
/** * Interface called by the AN SDK to request an ad from the mediating SDK. * * @param mBC the object which will be called with events from the 3d party SDK * @param activity the activity from which this is launched * @param parameter String parameter received from the server for instantiation of this object * @param adUnitID The 3rd party placement , in adMob this is the adUnitID * @param width Width of the ad * @param height Height of the ad */ @Override public View requestAd( MediatedBannerAdViewController mBC, Activity activity, String parameter, String adUnitID, int width, int height, TargetingParameters targetingParameters) { adListener = new AdMobAdListener(mBC, super.getClass().getSimpleName()); adListener.printToClog( String.format(" - requesting an ad: [%s, %s, %dx%d]", parameter, adUnitID, width, height)); admobAV = new AdView(activity, new AdSize(width, height), adUnitID); admobAV.setAdListener(adListener); AdRequest ar = new AdRequest(); switch (targetingParameters.getGender()) { case UNKNOWN: break; case FEMALE: ar.setGender(AdRequest.Gender.FEMALE); break; case MALE: ar.setGender(AdRequest.Gender.MALE); break; } AdMobAdapterExtras extras = new AdMobAdapterExtras(); if (targetingParameters.getAge() != null) { extras.addExtra("Age", targetingParameters.getAge()); } for (Pair<String, String> p : targetingParameters.getCustomKeywords()) { extras.addExtra(p.first, p.second); } if (targetingParameters.getLocation() != null) { ar.setLocation(targetingParameters.getLocation()); } ar.setNetworkExtras(extras); admobAV.loadAd(ar); return admobAV; }