本文整理汇总了Java中com.google.android.gms.ads.AdRequest.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java AdRequest.Builder方法的具体用法?Java AdRequest.Builder怎么用?Java AdRequest.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.ads.AdRequest
的用法示例。
在下文中一共展示了AdRequest.Builder方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showFullScreenAdsIfRequired
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
public static void showFullScreenAdsIfRequired(final StateActivity activity) {
if (Premium.isPremiumUser(activity)) return;
final InterstitialAd interstitialAd = new InterstitialAd(activity.getApplicationContext());
interstitialAd.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_INTERSTITIAL);
AdRequest.Builder request = new AdRequest.Builder();
if (BuildConfig.DEBUG) {
request.addTestDevice(TEST_DEVICE_ID);
}
interstitialAd.loadAd(request.build());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
if (!activity.isFinishing() && activity.isActivityVisible()) {
interstitialAd.show();
}
}
});
}
示例2: requestNewRewardedVideo
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
private void requestNewRewardedVideo() {
if (_config == null) { return; }
AdRequest.Builder adRB = new AdRequest.Builder();
if (BuildConfig.DEBUG) {
adRB.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRB.addTestDevice(Utils.getDeviceId(activity));
}
String ad_unit_id = _config.optString("RewardedVideoAdId", "");
if (ad_unit_id.length() <= 0) {
Utils.d("AdMob:RewardedVideo:UnitId:NotProvided");
ad_unit_id = activity.getString(R.string.rewarded_video_ad_unit_id);
}
mrv.loadAd(ad_unit_id, adRB.build());
}
示例3: createadmob
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
private AdView createadmob() {
AdView mAdView = new AdView(this);
mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
mAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
if (admob_test_mode)
// Optionally populate the ad request builder.
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());
return mAdView;
}
示例4: loadAd
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
public static void loadAd(final View view){
final Builder builder = new AdRequest.Builder();
builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); // Emulator
// Add test devices
final String[] testDevices = view.getContext().getString(R.string.testDevices).split(",");
for (String testDevice:testDevices){
builder.addTestDevice(testDevice);
}
final AdView adView = (AdView) view.findViewById(R.id.adView);
adView.loadAd(builder.build());
}
示例5: requestNewRewardedVideo
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
private void requestNewRewardedVideo(RewardedVideoAd mrv, String unitid) {
Utils.d("AdMob:Loading:RewardedAd:For: "+unitid);
AdRequest.Builder adRB = new AdRequest.Builder();
if (BuildConfig.DEBUG) {
adRB.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRB.addTestDevice(Utils.getDeviceId(activity));
}
mrv.loadAd(unitid, adRB.build());
}
示例6: requestNewInterstitial
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
private void requestNewInterstitial() {
AdRequest.Builder adRB = new AdRequest.Builder();
if (BuildConfig.DEBUG) {
adRB.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRB.addTestDevice(Utils.getDeviceId(activity));
}
AdRequest adRequest = adRB.build();
mInterstitialAd.loadAd(adRequest);
}
示例7: createadmob
import com.google.android.gms.ads.AdRequest; //导入方法依赖的package包/类
private RelativeLayout createadmob() {
AdSize adSize = AdSize.SMART_BANNER;
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
if (screenInches > 8) { // > 728 X 90
adSize = AdSize.LEADERBOARD;
} else if (screenInches > 6) { // > 468 X 60
adSize = AdSize.MEDIUM_RECTANGLE;
} else { // > 320 X 50
adSize = AdSize.BANNER;
}
adSize = AdSize.MEDIUM_RECTANGLE;
final AdView mAdView = new AdView(this);
mAdView.setAdSize(adSize);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
if (admob_test_mode)
// Optionally populate the ad request builder.
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());
DisplayMetrics displaymetrics = new DisplayMetrics();
final RelativeLayout layout = AdGoogleDisplaySupport.initialSupport(this, displaymetrics);
final double ratio = AdGoogleDisplaySupport.ratioMatching(displaymetrics);
final int ad_height = AdGoogleDisplaySupport.defaultHeight(displaymetrics);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (ad_height * ratio));
// get display info
/* G.display_w = displayMetrics.widthPixels;
G.display_h = displayMetrics.heightPixels;
G.scale = Math.max(G.display_w/1280.0f, G.display_h/800.0f);*/
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
int h = mAdView.getLayoutParams().height;
AdGoogleDisplaySupport.scale(mAdView, ratio);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (h * ratio));
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
}
});
layout.addView(mAdView);
return layout;
}