Rewarded Video Integration for Android (Chinese)
第 1 步. 实现激励视频 Listener
IronSource SDK 会在广告可用及完成时触发多个事件通知您,以便您知道何时奖励用户。 SDK 将就下列所有可能事件通知您的 listener:
IronSource.setRewardedVideoListener(new RewardedVideoListener() { /** * Invoked when the RewardedVideo ad view has opened. * Your Activity will lose focus. Please avoid performing heavy * tasks till the video ad will be closed. */ @Override public void onRewardedVideoAdOpened() { } /*Invoked when the RewardedVideo ad view is about to be closed. Your activity will now regain its focus.*/ @Override public void onRewardedVideoAdClosed() { } /** * Invoked when there is a change in the ad availability status. * * @param - available - value will change to true when rewarded videos are *available. * You can then show the video by calling showRewardedVideo(). * Value will change to false when no videos are available. */ @Override public void onRewardedVideoAvailabilityChanged(boolean available) { //Change the in-app 'Traffic Driver' state according to availability. } /** * Invoked when the video ad starts playing. */ @Override public void onRewardedVideoAdStarted() { } /*Invoked when the video ad finishes playing.*/ @Override public void onRewardedVideoAdEnded() { } /** * Invoked when the user completed the video and should be rewarded. * If using server-to-server callbacks you may ignore this events and wait *for the callback from the ironSource server. * * @param - placement - the Placement the user completed a video from. */ @Override public void onRewardedVideoAdRewarded(Placement placement) { /** here you can reward the user according to the given amount. String rewardName = placement.getRewardName(); int rewardAmount = placement.getRewardAmount(); */ } /* Invoked when RewardedVideo call to show a rewarded video has failed * IronSourceError contains the reason for the failure. */ @Override public void onRewardedVideoAdShowFailed(IronSourceError error) { } });
第 2 步. 向您的用户显示视频广告
通过正确实现 RewardedVideoListener 及其各种函数,您即可通过 onVideoAvailabilityChanged 回调接收可用状态。
boolean available = IronSource.isRewardedVideoAvailable();
或者,按以下方式直接调用索取广告可用状态:
一旦广告网络有可用视频时,您便已准备好向用户展示此视频广告。此时是插入触发器,以鼓励用户观看视频广告的理想时机。 利用 ironSource 广告展示位置工具,您可自定义优化激励视频体验。此工具使您可以依奖励不同而从不同位置向用户展示视频。您可使用以下函数,定义您希望展示广告的确切位置。请前往广告展示位置文档了解更多细节信息。 通过调用 ironSource 类的 showRewardedVideo() 方法,您可以向用户展示视频广告,并定义您希望广告展示的确切位置。此展示位置的奖励设置将从 ironSource 服务器中抓取;
IronSource.showRewardedVideo(placementName);
要获取关于每个广告展示位置的具体奖励详情,您可调用以下代码:
Placement placement = IronSource.getRewardedVideoPlacementInfo("placementName"); // Null can be returned instead of a placement if the placementName is not valid. if (placement != null) { String rewardName = placement.getRewardName(); int rewardAmount = placement.getRewardAmount(); }
除 ironSource 广告展示位置外,您现在可为所选展示位置广告配置频次和预算节奏。频次和预算节奏可通过限制在给定时间内的总广告投放数来提升应用的用户体验。请在此处了解更多关于频次和节奏的信息。 动态 UserID用于验证 AdRewarded Transactions 动态 UserID 是在会话中可更改的参数,其可在服务器至服务器广告奖励回调中接收它。此参数可帮助验证 AdRewarded transactions,其必须在调用 ShowRewardedVideo 前设置: ironSource SDK 将在用户每次成功完成一条视频时触发 onRewardedVideoAdRewarded 事件。 RewardedVideoListener 将就地接收此事件,以便您成功奖励用户。 展示位置对象同时包括了您在 ironSource Admin中定义的 奖励名称 & 奖励总额: 首次集成小技巧 若您是第一次对您的应用进行集成,则您的应用在 ironSource 控制台中默认处于 ‘测试模式‘。当应用处于测试模式时, ironSource SDK 将打印更多日志到控制台,以便提供更多 SDK 处理细节。要测试您的广告资源,请设置您的测试设备。在您开启真实广告资源前,您只会收到测试广告,并且不会因此获得收入。当您的应用准备好投放真实广告资源时,请确保在Ad Units页面选择 Go Live! 。 完成! 您现在已在您的应用中设置好投放激励视频广告!IronSource.isRewardedVideoPlacementCapped("Your Placements");
IronSource.setDynamicUserId("UserID");
第 3 步. 奖励用户
public void onRewardedVideoAdRewarded(Placement placement)
{
//TODO - here you can reward the user according to the given amount
String rewardName = placement.getRewardName();
int rewardAmount = placement.getRewardAmount();
}