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; }
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); }
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")); }
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"); } }
public void show_rewarded_video() { if (!isInitialized() || reward_ads.size() <= 0) { return; } RewardedVideoAd mrv = (RewardedVideoAd) reward_ads.values().toArray()[0]; if (mrv.isLoaded()) { mrv.show(); } else { Utils.d("AdMob:RewardedVideo:NotLoaded"); } }
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()); }
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); } } }
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); } } }
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); } } }
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()); }
public void emitRewardedVideoStatus(final String unitid) { RewardedVideoAd mrv = reward_ads.get(unitid); Utils.callScriptFunc("AdMob", "AdMob_Video", buildStatus(unitid, mrv.isLoaded() ? "loaded" : "not_loaded")); }
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; }
private void reloadRewardedVideo(final String unitid) { RewardedVideoAd mrv = reward_ads.get(unitid); requestNewRewardedVideo(mrv, unitid); }
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()); } }); }
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; }