use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.
the class XandrNativeInAppGAMDemoActivity method loadInAppNative.
private void loadInAppNative() {
removePreviousAds();
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
NativeAdUnit nativeAdUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
adUnit = nativeAdUnit;
ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS);
try {
NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
nativeAdUnit.addEventTracker(tracker);
} catch (Exception e) {
e.printStackTrace();
}
NativeTitleAsset title = new NativeTitleAsset();
title.setLength(90);
title.setRequired(true);
nativeAdUnit.addAsset(title);
NativeImageAsset icon = new NativeImageAsset();
icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
icon.setWMin(20);
icon.setHMin(20);
icon.setRequired(true);
nativeAdUnit.addAsset(icon);
NativeImageAsset image = new NativeImageAsset();
image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
image.setHMin(200);
image.setWMin(200);
image.setRequired(true);
nativeAdUnit.addAsset(image);
NativeDataAsset data = new NativeDataAsset();
data.setLen(90);
data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
data.setRequired(true);
nativeAdUnit.addAsset(data);
NativeDataAsset body = new NativeDataAsset();
body.setRequired(true);
body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
nativeAdUnit.addAsset(body);
NativeDataAsset cta = new NativeDataAsset();
cta.setRequired(true);
cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
nativeAdUnit.addAsset(cta);
final AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
// Fetching the demannd using OnCompleteListener
nativeAdUnit.fetchDemand(adManagerAdRequest, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
if (resultCode == ResultCode.SUCCESS) {
loadDfp(adManagerAdRequest);
} else {
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
refreshCount++;
XandrNativeInAppGAMDemoActivity.this.resultCode = resultCode;
request = adManagerAdRequest;
}
});
// ================================================================================
// SAMPLE CODE: Fetching the demand using OnCompleteListener2
// ================================================================================
/*
nativeAdUnit.fetchDemand(new OnCompleteListener2() {
@Override
public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
if (resultCode == ResultCode.SUCCESS) {
final AdManagerAdRequest.Builder adManagerAdRequestBuilder = new AdManagerAdRequest.Builder();
for (String key: unmodifiableMap.keySet()) {
adManagerAdRequestBuilder.addCustomTargeting(key, unmodifiableMap.get(key));
}
loadDfp(adManagerAdRequestBuilder.build());
}
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
});
*/
// ================================================================================
// SAMPLE CODE: END
// ================================================================================
}
use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.
the class XandrNativeInBannerGamDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
adUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
adFrame.removeAllViews();
final AdManagerAdView nativeAdView = new AdManagerAdView(this);
nativeAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
LogUtil.d("ad loaded");
}
});
nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
nativeAdView.setAdSizes(AdSize.FLUID);
adFrame.addView(nativeAdView);
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit;
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
try {
NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
nativeAdUnit.addEventTracker(tracker);
} catch (Exception e) {
e.printStackTrace();
}
NativeTitleAsset title = new NativeTitleAsset();
title.setLength(90);
title.setRequired(true);
nativeAdUnit.addAsset(title);
NativeImageAsset icon = new NativeImageAsset();
icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
icon.setWMin(20);
icon.setHMin(20);
icon.setRequired(true);
nativeAdUnit.addAsset(icon);
NativeImageAsset image = new NativeImageAsset();
image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
image.setHMin(200);
image.setWMin(200);
image.setRequired(true);
nativeAdUnit.addAsset(image);
NativeDataAsset data = new NativeDataAsset();
data.setLen(90);
data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
data.setRequired(true);
nativeAdUnit.addAsset(data);
NativeDataAsset body = new NativeDataAsset();
body.setRequired(true);
body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
nativeAdUnit.addAsset(body);
NativeDataAsset cta = new NativeDataAsset();
cta.setRequired(true);
cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
nativeAdUnit.addAsset(cta);
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
nativeAdUnit.setAutoRefreshPeriodMillis(millis);
nativeAdUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
nativeAdView.loadAd(request);
}
});
}
use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.
the class RubiconBannerGamDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_300x250_RUBICON);
String adSizeName = getIntent().getStringExtra(Constants.AD_SIZE_NAME);
int width = 0;
int height = 0;
String[] wAndH = adSizeName.split("x");
width = Integer.valueOf(wAndH[0]);
height = Integer.valueOf(wAndH[1]);
adUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_RUBICON, width, height);
BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
adUnit.setParameters(parameters);
// pre GAM v20.0
// final PublisherAdView amBanner = new PublisherAdView(this);
final AdManagerAdView amBanner = new AdManagerAdView(this);
amBanner.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250_RUBICON);
amBanner.setAdSizes(new AdSize(width, height));
FrameLayout adFrame = findViewById(R.id.adFrame);
adFrame.removeAllViews();
adFrame.addView(amBanner);
amBanner.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {
@Override
public void success(int width, int height) {
amBanner.setAdSizes(new AdSize(width, height));
}
@Override
public void failure(@NonNull PbFindSizeError error) {
Log.d("MyTag", "error: " + error);
}
});
}
});
// pre GAM v20.0
// final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
// region PrebidMobile Mobile API 1.0 usage
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
// pre GAM v20.0
// PublisherAdRequest request = builder.build();
AdManagerAdRequest request = builder.build();
amBanner.loadAd(request);
refreshCount++;
RubiconBannerGamDemoActivity.this.resultCode = resultCode;
}
});
}
use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.
the class RubiconBannerVideoGamDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_VAST_RUBICON);
VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
parameters.setMimes(Arrays.asList("video/mp4"));
parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
// parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
// parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
parameters.setPlacement(Signals.Placement.InBanner);
// parameters.setPlacement(new Signals.Placement(2));
VideoAdUnit adUnit = new VideoAdUnit("1001-1", 300, 250);
adUnit.setParameters(parameters);
this.adUnit = adUnit;
final AdManagerAdView amBanner = new AdManagerAdView(this);
amBanner.setAdUnitId(Constants.DFP_VAST_ADUNIT_ID_RUBICON);
amBanner.setAdSizes(new AdSize(300, 250));
FrameLayout adFrame = findViewById(R.id.adFrame);
adFrame.removeAllViews();
adFrame.addView(amBanner);
amBanner.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {
@Override
public void success(int width, int height) {
amBanner.setAdSizes(new AdSize(width, height));
}
@Override
public void failure(@NonNull PbFindSizeError error) {
Log.d("MyTag", "error: " + error);
}
});
}
});
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
// region PrebidMobile Mobile API 1.0 usage
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
amBanner.loadAd(request);
}
});
}
use of org.prebid.mobile.ResultCode in project prebid-mobile-android by prebid.
the class RubiconInterstitialVideoGamDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_VAST_RUBICON);
VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
parameters.setMimes(Arrays.asList("video/mp4"));
parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
// parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
// parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
VideoInterstitialAdUnit adUnit = new VideoInterstitialAdUnit("1001-1");
adUnit.setParameters(parameters);
this.adUnit = adUnit;
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
AdManagerInterstitialAd.load(RubiconInterstitialVideoGamDemoActivity.this, Constants.DFP_VAST_ADUNIT_ID_RUBICON, request, new AdManagerInterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
super.onAdLoaded(adManagerInterstitialAd);
adManagerInterstitialAd.show(RubiconInterstitialVideoGamDemoActivity.this);
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(RubiconInterstitialVideoGamDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(RubiconInterstitialVideoGamDemoActivity.this);
}
builder.setTitle("Failed to load AdManager interstitial ad").setMessage("Error: " + loadAdError.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
}
});
}
});
}
Aggregations