本文整理汇总了Java中com.google.android.gms.ads.reward.RewardedVideoAd类的典型用法代码示例。如果您正苦于以下问题:Java RewardedVideoAd类的具体用法?Java RewardedVideoAd怎么用?Java RewardedVideoAd使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RewardedVideoAd类属于com.google.android.gms.ads.reward包,在下文中一共展示了RewardedVideoAd类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showAd
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public PluginResult showAd(final boolean show, final CallbackContext callbackContext) {
if (rewardedVideoAd == null) {
return new PluginResult(PluginResult.Status.ERROR, "rewardedVideoAd is null, call createRewardVideo first.");
}
CordovaInterface cordova = plugin.cordova;
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (rewardedVideoAd instanceof RewardedVideoAd) {
RewardedVideoAd rvad = rewardedVideoAd;
if (rvad.isLoaded()) {
rvad.show();
}
}
if (callbackContext != null) {
callbackContext.success();
}
}
});
return null;
}
示例2: init
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void init (FirebaseApp firebaseApp) {
mFirebaseApp = firebaseApp;
AdMobConfig = FireBase.getConfig().optJSONObject("Ads");
MobileAds.initialize(activity, AdMobConfig.optString("AppId"));
if (AdMobConfig.optBoolean("BannerAd", false)) { createBanner(); }
if (AdMobConfig.optBoolean("InterstitialAd", false)) { createInterstitial(); }
if (AdMobConfig.optBoolean("RewardedVideoAd", false)) {
reward_ads = new HashMap<String, RewardedVideoAd>();
String ad_unit_id = AdMobConfig.optString("RewardedVideoAdId", "");
List<String> ad_units = new ArrayList<String>();
if (ad_unit_id.length() <= 0) {
Utils.d("AdMob:RewardedVideo:UnitId:NotProvided");
ad_units.add(activity.getString(R.string.rewarded_video_ad_unit_id));
} else {
ad_units = Arrays.asList(ad_unit_id.split(","));
Utils.d("AdMob:RewardedVideo:" +
String.valueOf(ad_units.size()) +":UnitIdS:Found");
}
for (String id : ad_units) {
RewardedVideoAd mrv = createRewardedVideo(id);
requestNewRewardedVideo(mrv, id);
reward_ads.put(id, mrv);
}
}
mAdSize = new Dictionary();
mAdSize.put("width", 0);
mAdSize.put("height", 0);
}
示例3: emitRewardedVideoStatus
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void emitRewardedVideoStatus() {
RewardedVideoAd mrv = (RewardedVideoAd) reward_ads.values().toArray()[0];
String id = (String) reward_ads.keySet().toArray()[0];
Utils.callScriptFunc("AdMob", "AdMob_Video",
buildStatus(id, mrv.isLoaded() ? "loaded" : "not_loaded"));
}
示例4: show_rewarded_video
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void show_rewarded_video(final String id) {
if (!isInitialized() || reward_ads.size() <= 0) { return; }
RewardedVideoAd mrv = (RewardedVideoAd) reward_ads.get(id);
if (mrv.isLoaded()) { mrv.show(); }
else { Utils.d("AdMob:RewardedVideo:NotLoaded"); }
}
示例5: requestNewRewardedVideo
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
private void requestNewRewardedVideo(RewardedVideoAd mrv, String unitid) {
Utils.d("AdMob:Loading:RewardedAd:For: "+unitid);
AdRequest.Builder adRB = new AdRequest.Builder();
if (BuildConfig.DEBUG) {
adRB.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
adRB.addTestDevice(Utils.getDeviceId(activity));
}
mrv.loadAd(unitid, adRB.build());
}
示例6: onPause
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void onPause() {
if (mAdView != null) { mAdView.pause(); }
if (reward_ads != null) {
for (Map.Entry<String, RewardedVideoAd> entry : reward_ads.entrySet()) {
entry.getValue().pause(activity);
}
}
}
示例7: onResume
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void onResume() {
if (mAdView != null) { mAdView.resume(); }
if (reward_ads != null) {
for (Map.Entry<String, RewardedVideoAd> entry : reward_ads.entrySet()) {
entry.getValue().resume(activity);
}
}
}
示例8: onStop
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public void onStop() {
if (mAdView != null) { mAdView.destroy(); }
if (reward_ads != null) {
for (Map.Entry<String, RewardedVideoAd> entry : reward_ads.entrySet()) {
entry.getValue().destroy(activity);
}
}
}
示例9: showVideoAd
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
static void showVideoAd(Activity activity) {
final RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(activity);
ad.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
ad.show();
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
}
@Override
public void onRewarded(RewardItem rewardItem) {
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
});
ad.loadAd(activity.getString(R.string.reward_video_ad_unit_id), new AdRequest.Builder().build());
}
示例10: createRewardedVideo
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public RewardedVideoAd createRewardedVideo(final String unitid) {
RewardedVideoAd mrv = MobileAds.getRewardedVideoAdInstance(activity);
mrv.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
Utils.d("AdMob:Video:Loaded");
Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, "loaded"));
}
@Override
public void onRewarded(RewardItem rewardItem) {
Utils.d("AdMob:Rewarded:Success");
Dictionary ret = new Dictionary();
ret.put("RewardType", rewardItem.getType());
ret.put("RewardAmount", rewardItem.getAmount());
ret.put("unit_id", unitid);
Utils.callScriptFunc("AdMob", "AdMobReward", ret);
reloadRewardedVideo(unitid);
}
@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Utils.d("AdMob:VideoLoad:Failed");
Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, "load_failed"));
reloadRewardedVideo(unitid);
}
@Override
public void onRewardedVideoAdClosed() {
Utils.d("AdMob:VideoAd:Closed");
Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, "closed"));
reloadRewardedVideo(unitid);
}
@Override
public void onRewardedVideoAdLeftApplication() {
Utils.d("AdMob:VideoAd:LeftApp");
}
@Override
public void onRewardedVideoAdOpened() {
Utils.d("AdMob:VideoAd:Opended");
//Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, "opened"));
}
@Override
public void onRewardedVideoStarted() {
Utils.d("Reward:VideoAd:Started");
//Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, "started"));
}
});
return mrv;
}
示例11: reloadRewardedVideo
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
private void reloadRewardedVideo(final String unitid) {
RewardedVideoAd mrv = reward_ads.get(unitid);
requestNewRewardedVideo(mrv, unitid);
}
示例12: loadAndshowRewardedVideo
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
private Single<Boolean> loadAndshowRewardedVideo(final String id) {
return Single.create(new SingleOnSubscribe<Boolean>() {
@Override
public void subscribe(@NonNull final SingleEmitter<Boolean> e) throws Exception {
final RewardedVideoAd mAd = MobileAds.getRewardedVideoAdInstance(application);
mAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
boolean rewarded = false;
@Override
public void onRewardedVideoAdLoaded() {
mAd.show();
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
e.onSuccess(rewarded);
}
@Override
public void onRewarded(RewardItem rewardItem) {
rewarded = true;
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
e.onError(new AdError());
}
});
final AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
if (debug) {
adRequestBuilder.addTestDevice(DeviceIdFounder.getDeviceId(application));
}
mAd.loadAd(id, adRequestBuilder.build());
}
});
}
示例13: showRewardedVideo
import com.google.android.gms.ads.reward.RewardedVideoAd; //导入依赖的package包/类
public AdsManager showRewardedVideo(final int stringId, final AdVideoClosedListener adVideoClosedListener) {
if (BuildConfig.DEBUG && !showAdsOnDebug) {
adVideoClosedListener.onAdClosedWithReward();
} else {
final RewardedVideoAd mAd = MobileAds.getRewardedVideoAdInstance(context);
mAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
boolean rewarded = false;
@Override
public void onRewardedVideoAdLoaded() {
mAd.show();
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
if (rewarded) {
adVideoClosedListener.onAdClosedWithReward();
} else {
adVideoClosedListener.onAdClosedWithoutReward();
}
}
@Override
public void onRewarded(RewardItem rewardItem) {
rewarded = true;
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
});
final AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
if (BuildConfig.DEBUG) {
adRequestBuilder.addTestDevice(DeviceIdFounder.getDeviceId(context));
}
mAd.loadAd(context.getString(stringId), adRequestBuilder.build());
}
return this;
}