This class is used to request and display a rewarded video.
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener { private RewardedVideoAd mAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAd = MobileAds.getRewardedVideoAdInstance(this); mAd.setUserId("userId"); mAd.setRewardedVideoAdListener(this); AdRequest adRequest = new AdRequest.Builder().build(); mAd.loadAd("adUnitId", adRequest); } @Override public void onRewardedVideoAdLoaded() { findViewById(R.id.display_button).setVisibility(View.VISIBLE); } public void onDisplayButtonClicked(View view) { if (mAd.isLoaded()) { mAd.show(); } } @Override public void onRewarded(RewardItem rewardItem) { Toast.makeText( this, "onRewarded! currency: " + rewardItem.getType() + " amount: " + rewardItem.getAmount(), Toast.LENGTH_SHORT).show(); } @Override public void onResume() { super.onResume(); mAd.resume(this); } @Override public void onPause() { mAd.pause(this); super.onPause(); } @Override public void onDestroy() { mAd.destroy(this); super.onDestroy(); } }
Public Method Summary
abstract void | |
abstract void |
destroy()
This method is deprecated. Replaced by
destroy(Context)
|
abstract Bundle |
getAdMetadata()
Gets all available ad metadata for this
RewardedVideoAd .
|
abstract String |
getCustomData()
Returns the custom data set by
setCustomData(String) , or null if custom data has not been set.
|
abstract String |
getMediationAdapterClassName()
Returns the mediation adapter class name.
|
abstract RewardedVideoAdListener | |
abstract String |
getUserId()
Returns the user id set by
setUserId(String) .
|
abstract boolean |
isLoaded()
Returns
true if a rewarded video ad is available and is ready to
be shown.
|
abstract void |
loadAd(String adUnitId,
PublisherAdRequest adRequest)
Requests for a rewarded video ad using PublisherAdRequest.
|
abstract void | |
abstract void | |
abstract void |
pause()
This method is deprecated. Replaced by
pause(Context)
|
abstract void | |
abstract void |
resume()
This method is deprecated. Replaced by
resume(Context)
|
abstract void |
setAdMetadataListener(AdMetadataListener
listener)
Sets the
AdMetadataListener
for this RewardedVideoAd .
|
abstract void | |
abstract void |
setImmersiveMode(boolean immersiveModeEnabled)
Sets a flag that controls if ads subsequently loaded by this object will be
displayed in immersive mode.
|
abstract void |
setRewardedVideoAdListener(RewardedVideoAdListener
listener)
Sets a
RewardedVideoAdListener for this RewardedVideoAd .
|
abstract void | |
abstract void |
show()
Shows rewarded video ad if available.
|
Public Methods
public abstract void destroy (Context context)
Destroys the RewardedVideoAd
.
This method should be called in the parent Activity's onDestroy()
method.
public abstract void destroy ()
This method is deprecated.
Replaced by
destroy(Context)
Destroys the RewardedVideoAd
.
This method should be called in the parent Activity's onDestroy()
method.
public abstract Bundle getAdMetadata ()
Gets all available ad metadata for this RewardedVideoAd
.
Ad metadata is empty if no ad has loaded or the loaded ad doesn't have metadata. Ad
metadata may update after loading. Use
onAdMetadataChanged()
to listen for changes.
public abstract String getCustomData ()
Returns the custom data set by
setCustomData(String)
, or null if custom data has not been set.
public abstract String getMediationAdapterClassName ()
Returns the mediation adapter class name. In the case of a mediated ad response,
this is the name of the class that was responsible for performing the ad request and
rendering the ad. For non-mediated responses, this value will be null
.
public abstract RewardedVideoAdListener getRewardedVideoAdListener ()
Returns the RewardedVideoAdListener
set by
setRewardedVideoAdListener(RewardedVideoAdListener)
.
public abstract String getUserId ()
Returns the user id set by
setUserId(String)
.
public abstract boolean isLoaded ()
Returns true
if a rewarded video ad is available and is ready to be
shown.
public abstract void loadAd (String adUnitId, PublisherAdRequest adRequest)
Requests for a rewarded video ad using PublisherAdRequest.
public abstract void loadAd (String adUnitId, AdRequest adRequest)
Requests for a rewarded video ad.
public abstract void pause (Context context)
Pauses any extra processing associated with this RewardedVideoAd
.
This method should be called in the parent Activity's onPause()
method.
public abstract void pause ()
This method is deprecated.
Replaced by
pause(Context)
Pauses any extra processing associated with this RewardedVideoAd
.
This method should be called in the parent Activity's onPause()
method.
public abstract void resume (Context context)
Resumes an RewardedVideoAd
.
This method should be called in the parent Activity's onResume()
method.
public abstract void resume ()
This method is deprecated.
Replaced by
resume(Context)
Resumes an RewardedVideoAd
.
This method should be called in the parent Activity's onResume()
method.
public abstract void setAdMetadataListener (AdMetadataListener listener)
Sets the AdMetadataListener
for this RewardedVideoAd
.
public abstract void setCustomData (String customData)
Sets the custom data of the rewarded ad.
Sets the custom data to be used in server-to-server reward callbacks.
public abstract void setImmersiveMode (boolean immersiveModeEnabled)
Sets a flag that controls if ads subsequently loaded by this object will be
displayed in immersive mode. Call this method before show()
to affect subsequent rewarded video ads. 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 when displaying the ad.
public abstract void setRewardedVideoAdListener (RewardedVideoAdListener listener)
Sets a RewardedVideoAdListener
for this RewardedVideoAd
.
public abstract void setUserId (String userId)
Sets the user id of current user.
Sets the user id to be used in server-to-server reward callbacks.
public abstract void show ()
Shows rewarded video ad if available. Applications should check isLoaded()
before calling this method.