RewardedAd

public abstract class RewardedAd 

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 
 (); 
  
 } 
  
 }); 
  
 } 
  
 } 
 } 

Summary

Public constructors

Public methods

abstract Bundle

Gets all available ad metadata for this RewardedAd .

abstract @ NonNull String

Returns the ad unit ID.

abstract @ Nullable FullScreenContentCallback

Gets the FullScreenContentCallback for this RewardedAd .

abstract @ Nullable OnAdMetadataChangedListener

Gets the OnAdMetadataChangedListener for this RewardedAd .

abstract @ Nullable OnPaidEventListener

Gets the OnPaidEventListener for this RewardedAd .

abstract long

Gets the placement ID for this RewardedAd .

abstract @ NonNull ResponseInfo

Returns the ResponseInfo object for the loaded ad.

abstract @ NonNull RewardItem

Gets reward item for the loaded rewarded ad.

static boolean
isAdAvailable (@ NonNull Context  context, @ NonNull String  adUnitId)

This method is deprecated.

Use isAdAvailable instead.

static void
load (
    @ NonNull Context  context,
    @ NonNull String  adUnitId,
    @ NonNull AdManagerAdRequest  adManagerAdRequest,
    @ NonNull RewardedAdLoadCallback  loadCallback
)

Loads a RewardedAd .

static void
load (
    @ NonNull Context  context,
    @ NonNull String  adUnitId,
    @ NonNull AdRequest  adRequest,
    @ NonNull RewardedAdLoadCallback  loadCallback
)

Loads a RewardedAd .

static @ Nullable RewardedAd
pollAd (@ NonNull Context  context, @ NonNull String  adUnitId)

This method is deprecated.

Use pollAd instead.

abstract void
setFullScreenContentCallback (
    @ Nullable 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

Sets the OnAdMetadataChangedListener for this RewardedAd .

abstract void

Registers a callback to be invoked when this ad is estimated to have earned money.

abstract void
setPlacementId (long placementId)

Sets a placement ID for the rewarded ad.

abstract void

Sets ServerSideVerificationOptions for this RewardedAd .

abstract void
show (
    @ NonNull Activity  activity,
    @ NonNull OnUserEarnedRewardListener  onUserEarnedRewardListener
)

Shows the rewarded ad.

Public constructors

RewardedAd

public  RewardedAd 
()

Public methods

getAdMetadata

public abstract  Bundle 
 getAdMetadata 
()

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 onAdMetadataChanged to listen for changes.

getAdUnitId

public abstract @ NonNull 
 String 
 getAdUnitId 
()

Returns the ad unit ID.

getFullScreenContentCallback

public abstract @ Nullable 
 FullScreenContentCallback 
 getFullScreenContentCallback 
()

Gets the FullScreenContentCallback for this RewardedAd .

getOnAdMetadataChangedListener

public abstract @ Nullable 
 OnAdMetadataChangedListener 
 getOnAdMetadataChangedListener 
()

Gets the OnAdMetadataChangedListener for this RewardedAd .

getOnPaidEventListener

public abstract @ Nullable 
 OnPaidEventListener 
 getOnPaidEventListener 
()

Gets the OnPaidEventListener for this RewardedAd .

getPlacementId

public abstract long  getPlacementId 
()

Gets the placement ID for this RewardedAd .

getResponseInfo

public abstract @ NonNull 
 ResponseInfo 
 getResponseInfo 
()

Returns the ResponseInfo object for the loaded ad.

getRewardItem

public abstract @ NonNull 
 RewardItem 
 getRewardItem 
()

Gets reward item for the loaded rewarded ad.

isAdAvailable

public static boolean    isAdAvailable 
 
 
(@ NonNull 
 Context 
 context, @ NonNull 
 String 
 adUnitId)

Returns true if there is an available rewarded ad loaded from startPreload .

load

public static void  load 
(
    @ NonNull Context  context,
    @ NonNull String  adUnitId,
    @ NonNull AdManagerAdRequest  adManagerAdRequest,
    @ NonNull RewardedAdLoadCallback  loadCallback
)

Loads a RewardedAd .

Parameters
@ NonNull Context  context

The context.

@ NonNull String  adUnitId

The ad unit ID.

@ NonNull AdManagerAdRequest  adManagerAdRequest

A Google Ad Manager ad request with targeting information.

@ NonNull RewardedAdLoadCallback  loadCallback

A callback to be invoked when a rewarded ad finishes loading.

load

public static void  load 
(
    @ NonNull Context  context,
    @ NonNull String  adUnitId,
    @ NonNull AdRequest  adRequest,
    @ NonNull RewardedAdLoadCallback  loadCallback
)

Loads a RewardedAd .

Parameters
@ NonNull Context  context

The context.

@ NonNull String  adUnitId

The ad unit ID.

@ NonNull AdRequest  adRequest

An ad request with targeting information.

@ NonNull RewardedAdLoadCallback  loadCallback

A callback to be invoked when a rewarded ad finishes loading.

pollAd

public static @ Nullable 
 RewardedAd 
   pollAd 
 
 
(@ NonNull 
 Context 
 context, @ NonNull 
 String 
 adUnitId)

Retrieves the next rewarded ad loaded from startPreload , or null if no ad is available.

setFullScreenContentCallback

public abstract void  setFullScreenContentCallback 
(
    @ Nullable FullScreenContentCallback  fullScreenContentCallback
)

Registers a callback to be invoked when ads show and dismiss full screen content.

setImmersiveMode

public abstract void  setImmersiveMode 
(boolean immersiveModeEnabled)

Sets a flag that controls if this rewarded ad object will be displayed in immersive mode. Call this method before show . During show , 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.

setOnAdMetadataChangedListener

public abstract void  setOnAdMetadataChangedListener 
(
    @ Nullable OnAdMetadataChangedListener  listener
)

Sets the OnAdMetadataChangedListener for this RewardedAd .

setOnPaidEventListener

public abstract void  setOnPaidEventListener 
(@ Nullable 
 OnPaidEventListener 
 listener)

Registers a callback to be invoked when this ad is estimated to have earned money.

setPlacementId

public abstract void  setPlacementId 
(long placementId)

Sets a placement ID for the rewarded ad.

To ensure this placement ID is included in reporting, call this method before showing the ad.

Parameters
long placementId

A long integer provided by the AdMob UI for the configured placement.

setServerSideVerificationOptions

public abstract void  setServerSideVerificationOptions 
(
    @ Nullable ServerSideVerificationOptions  options
)

Sets ServerSideVerificationOptions for this RewardedAd .

show

public abstract void  show 
(
    @ NonNull Activity  activity,
    @ NonNull OnUserEarnedRewardListener  onUserEarnedRewardListener
)

Shows the rewarded ad.

Parameters
@ NonNull Activity  activity

The activity from which the rewarded ad should be shown.

@ NonNull OnUserEarnedRewardListener  onUserEarnedRewardListener

The listener to be notified when user earns a reward.

Create a Mobile Website
View Site in Mobile | Classic
Share by: