use of com.google.android.gms.ads.rewarded.RewardedAdLoadCallback 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);
}
use of com.google.android.gms.ads.rewarded.RewardedAdLoadCallback in project prebid-mobile-android by prebid.
the class RewardedAdWrapperTest method onAdMetadataChanged_WithMetadataContainsAdEvent_NotifyAppEventListener.
@Test
public void onAdMetadataChanged_WithMetadataContainsAdEvent_NotifyAppEventListener() {
final RewardedAdLoadCallback rewardedAdLoadCallback = getRewardedAdLoadCallback();
final RewardedAd mockRewardedAd = mock(RewardedAd.class);
final Bundle bundle = new Bundle();
bundle.putString(RewardedAdWrapper.KEY_METADATA, APP_EVENT);
when(mockRewardedAd.getAdMetadata()).thenReturn(bundle);
rewardedAdLoadCallback.onAdLoaded(mockRewardedAd);
verify(mMockListener, times(1)).onEvent(eq(AdEvent.APP_EVENT_RECEIVED));
}
use of com.google.android.gms.ads.rewarded.RewardedAdLoadCallback in project prebid-mobile-android by prebid.
the class RubiconRewardedVideoGamDemoActivity 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)));
RewardedVideoAdUnit adUnit = new RewardedVideoAdUnit("1001-1");
adUnit.setParameters(parameters);
this.adUnit = adUnit;
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
RewardedAd.load(RubiconRewardedVideoGamDemoActivity.this, Constants.DFP_REWARDED_ADUNIT_ID_RUBICON, request, new RewardedAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
super.onAdLoaded(rewardedAd);
rewardedAd.show(RubiconRewardedVideoGamDemoActivity.this, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
}
});
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
}
});
}
});
}
use of com.google.android.gms.ads.rewarded.RewardedAdLoadCallback in project prebid-mobile-android by prebid.
the class RewardedAdWrapperTest method onAdMetadataChangedMetadata_ContainsNoAdEvent_DoNothing.
@Test
public void onAdMetadataChangedMetadata_ContainsNoAdEvent_DoNothing() {
final RewardedAdLoadCallback rewardedAdLoadCallback = getRewardedAdLoadCallback();
final RewardedAd mockRewardedAd = mock(RewardedAd.class);
final Bundle bundle = new Bundle();
when(mockRewardedAd.getAdMetadata()).thenReturn(bundle);
rewardedAdLoadCallback.onAdLoaded(mockRewardedAd);
verify(mMockListener, times(0)).onEvent(eq(AdEvent.APP_EVENT_RECEIVED));
}
Aggregations