Search in sources :

Example 1 with OnUserEarnedRewardListener

use of com.google.android.gms.ads.OnUserEarnedRewardListener in project mopub-android-mediation by mopub.

the class GooglePlayServicesRewardedVideo method show.

@Override
protected void show() {
    MoPubLog.log(getAdNetworkId(), SHOW_ATTEMPTED, ADAPTER_NAME);
    if (mRewardedAd != null) {
        if (mContext instanceof Activity) {
            mRewardedAd.show((Activity) mContext, new OnUserEarnedRewardListener() {

                @Override
                public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
                    Preconditions.checkNotNull(rewardItem);
                    MoPubLog.log(getAdNetworkId(), SHOULD_REWARD, ADAPTER_NAME, rewardItem.getAmount(), rewardItem.getType());
                    if (mInteractionListener != null) {
                        mInteractionListener.onAdComplete(MoPubReward.success(rewardItem.getType(), rewardItem.getAmount()));
                    }
                }
            });
        } else {
            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);
            }
        }
    } else {
        MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "Failed to show " + "Google rewarded video because it wasn't ready yet.");
        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);
        }
    }
}
Also used : OnUserEarnedRewardListener(com.google.android.gms.ads.OnUserEarnedRewardListener) RewardItem(com.google.android.gms.ads.rewarded.RewardItem) Activity(android.app.Activity)

Example 2 with OnUserEarnedRewardListener

use of com.google.android.gms.ads.OnUserEarnedRewardListener 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);
                }
            });
        }
    });
}
Also used : LoadAdError(com.google.android.gms.ads.LoadAdError) OnUserEarnedRewardListener(com.google.android.gms.ads.OnUserEarnedRewardListener) RewardedAdLoadCallback(com.google.android.gms.ads.rewarded.RewardedAdLoadCallback) RewardedVideoAdUnit(org.prebid.mobile.RewardedVideoAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) RewardedAd(com.google.android.gms.ads.rewarded.RewardedAd) NonNull(androidx.annotation.NonNull) RewardItem(com.google.android.gms.ads.rewarded.RewardItem) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Aggregations

OnUserEarnedRewardListener (com.google.android.gms.ads.OnUserEarnedRewardListener)2 RewardItem (com.google.android.gms.ads.rewarded.RewardItem)2 Activity (android.app.Activity)1 NonNull (androidx.annotation.NonNull)1 LoadAdError (com.google.android.gms.ads.LoadAdError)1 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)1 RewardedAd (com.google.android.gms.ads.rewarded.RewardedAd)1 RewardedAdLoadCallback (com.google.android.gms.ads.rewarded.RewardedAdLoadCallback)1 OnCompleteListener (org.prebid.mobile.OnCompleteListener)1 ResultCode (org.prebid.mobile.ResultCode)1 RewardedVideoAdUnit (org.prebid.mobile.RewardedVideoAdUnit)1 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)1