com.google.android.gms.ads.reward.RewardedVideoAd |
This class is used to request and display a rewarded video.
public class MainActivity extends ActionBarActivity implements RewardedVideoAdListener { private RewardedVideoAd mAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAd = MobileAds.getRewardedVideoAdInstance(this); 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 Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Destroys the
RewardedVideoAd . | |||||||||||
This method is deprecated.
Replaced by
destroy(Context)
| |||||||||||
Returns the mediation adapter class name.
| |||||||||||
Returns the
RewardedVideoAdListener set by setRewardedVideoAdListener(RewardedVideoAdListener) . | |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
Returns
true if a rewarded video ad is available and is ready to be shown. | |||||||||||
Requests for a rewarded video ad.
| |||||||||||
Pauses any extra processing associated with this
RewardedVideoAd . | |||||||||||
This method is deprecated.
Replaced by
pause(Context)
| |||||||||||
Resumes an
RewardedVideoAd . | |||||||||||
This method is deprecated.
Replaced by
resume(Context)
| |||||||||||
Sets a flag that controls if ads subsequently loaded by this object will be displayed in
immersive mode.
| |||||||||||
Sets a
RewardedVideoAdListener for this RewardedVideoAd . | |||||||||||
This method is deprecated.
No replacement.
| |||||||||||
Shows rewarded video ad if available.
|
Destroys the RewardedVideoAd
. This method should be called in the parent Activity's
onDestroy()
method.
Parameters | |
---|---|
context |
Context
|
This method is deprecated.
Replaced by destroy(Context)
Destroys the RewardedVideoAd
. This method should be called in the parent Activity's
onDestroy()
method.
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
.
Returns | |
---|---|
String |
Returns the RewardedVideoAdListener
set by setRewardedVideoAdListener(RewardedVideoAdListener)
.
Returns | |
---|---|
RewardedVideoAdListener |
This method is deprecated.
No replacement.
Returns the user id set by setUserId(String)
. This method will always return null.
Returns | |
---|---|
String |
Returns true
if a rewarded video ad is available and is ready to be shown.
Returns | |
---|---|
boolean |
Requests for a rewarded video ad.
Parameters | |
---|---|
adUnitId |
String
|
adRequest |
AdRequest
|
Pauses any extra processing associated with this RewardedVideoAd
. This method should be
called in the parent Activity's onPause()
method.
Parameters | |
---|---|
context |
Context
|
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.
Resumes an RewardedVideoAd
. This method should be called in the parent Activity's
onResume()
method.
Parameters | |
---|---|
context |
Context
|
This method is deprecated.
Replaced by resume(Context)
Resumes an RewardedVideoAd
. This method should be called in the parent Activity's
onResume()
method.
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.
Parameters | |
---|---|
immersiveModeEnabled |
boolean
|
Sets a RewardedVideoAdListener
for this RewardedVideoAd
.
Parameters | |
---|---|
listener |
RewardedVideoAdListener
|
This method is deprecated.
No replacement.
Sets the user id of current user. This method is a no-op.
Parameters | |
---|---|
userId |
String
|
Shows rewarded video ad if available. Applications should check isLoaded()
before
calling this method.