This class is used to request and display a rewarded ad.
public class MainActivity extends AppCompatActivity {
private RewardedAd rewardedAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FullScreenContentCallback fullScreenContentCallback =
new FullScreenContentCallback() {
@Override
public void onAdShowedFullScreenContent() {
// Code to be invoked when the ad showed full screen content.
}
@Override
public void onAdDismissedFullScreenContent() {
rewardedAd = null;
// Code to be invoked when the ad dismissed full screen content.
}
};
RewardedAd.load(
this,
"adUnitId",
new AdRequest.Builder().build(),
new RewardedAdLoadCallback() {
@Override
public void onAdLoaded(RewardedAd ad) {
findViewById(R.id.display_button).setVisibility(View.VISIBLE);
rewardedAd = ad;
rewardedAd.setFullScreenContentCallback(fullScreenContentCallback);
}
});
}
public void onDisplayButtonClicked(View view) {
if (rewardedAd != null) {
rewardedAd.show(
this,
new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
Toast.makeText(
MainActivity.this,
"onRewarded! currency: "
+ rewardItem.getType() + " amount: "
+ rewardItem.getAmount(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
| abstract Bundle |
getAdMetadata()
Gets all available ad metadata for this
RewardedAd.
|
| abstract String |
getAdUnitId()
Returns the ad unit ID.
|
| abstract FullScreenContentCallback |
getFullScreenContentCallback()
Gets the
FullScreenContentCallback
for this RewardedAd.
|
| abstract OnAdMetadataChangedListener |
getOnAdMetadataChangedListener()
Gets the
OnAdMetadataChangedListener for this RewardedAd.
|
| abstract OnPaidEventListener |
getOnPaidEventListener()
Gets the
OnPaidEventListener
for this RewardedAd.
|
| abstract ResponseInfo |
getResponseInfo()
Returns the
ResponseInfo
object for the loaded ad.
|
| abstract RewardItem |
getRewardItem()
Gets reward item for the loaded rewarded ad.
|
| static void |
load(Context
context, String adUnitId,
AdRequest
adRequest,
RewardedAdLoadCallback loadCallback)
Loads a
RewardedAd.
|
| static void |
load(Context
context, String adUnitId,
AdManagerAdRequest adManagerAdRequest,
RewardedAdLoadCallback loadCallback)
Loads a
RewardedAd.
|
| abstract void |
setFullScreenContentCallback(FullScreenContentCallback
fullScreenContentCallback)
Registers a callback to be invoked when ads show and dismiss full screen
content.
|
| abstract void |
setImmersiveMode(boolean immersiveModeEnabled)
Sets a flag that controls if this rewarded ad object will be displayed in
immersive mode.
|
| abstract void |
setOnAdMetadataChangedListener(OnAdMetadataChangedListener
listener)
Sets the
OnAdMetadataChangedListener for this RewardedAd.
|
| abstract void |
setOnPaidEventListener(OnPaidEventListener
listener)
Registers a callback to be invoked when this ad is estimated to have earned
money.
|
| abstract void |
setServerSideVerificationOptions(ServerSideVerificationOptions
options)
Sets
ServerSideVerificationOptions for this RewardedAd.
|
| abstract void |
show(Activity
activity, OnUserEarnedRewardListener
onUserEarnedRewardListener)
Shows the rewarded ad.
|
Gets all available ad metadata for this RewardedAd.
Ad metadata is empty if the loaded ad doesn't have metadata. Ad metadata may update
after loading. Use
OnAdMetadataChangedListener.onAdMetadataChanged() to listen for changes.
Returns the ad unit ID.
Gets the FullScreenContentCallback
for this RewardedAd.
Gets the
OnAdMetadataChangedListener for this RewardedAd.
Gets the OnPaidEventListener
for this RewardedAd.
Returns the ResponseInfo
object for the loaded ad.
Gets reward item for the loaded rewarded ad.
Loads a RewardedAd.
| context | The context. |
|---|---|
| adUnitId | The ad unit ID. |
| adRequest | An ad request with targeting information. |
| loadCallback | A callback to be invoked when a rewarded ad finishes loading. |
Loads a RewardedAd.
| context | The context. |
|---|---|
| adUnitId | The ad unit ID. |
| adManagerAdRequest | A Google Ad Manager ad request with targeting information. |
| loadCallback | A callback to be invoked when a rewarded ad finishes loading. |
Registers a callback to be invoked when ads show and dismiss full screen content.
Sets a flag that controls if this rewarded ad object will be displayed in immersive
mode. Call this method before
show(Activity, OnUserEarnedRewardListener). During
show(Activity, OnUserEarnedRewardListener), if this flag is on and immersive
mode is supported, SYSTEM_UI_FLAG_IMMERSIVE_STICKY & SYSTEM_UI_FLAG_HIDE_NAVIGATION
will be turned on for the rewarded ad.
Sets the
OnAdMetadataChangedListener for this RewardedAd.
Registers a callback to be invoked when this ad is estimated to have earned money.
Sets
ServerSideVerificationOptions for this RewardedAd.
Shows the rewarded ad.
| activity | The activity from which the rewarded ad should be shown. |
|---|---|
| onUserEarnedRewardListener | The listener to be notified when user earns a reward. |