Java Code Examples for com.google.android.gms.ads.MobileAds#getRewardedVideoAdInstance()

The following examples show how to use com.google.android.gms.ads.MobileAds#getRewardedVideoAdInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidAdMobRewardedVideo.java    From QtAndroidTools with MIT License 6 votes vote down vote up
private void createRewardedVideoAd()
{
    if(mRewardedVideoAd != null)
    {
        return;
    }

    SyncRunOnUiThread UiThread = new SyncRunOnUiThread(mActivityInstance, new SyncRunOnUiThread.SyncRunOnUiThreadListener()
    {
        public void runOnUIThread()
        {
            mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(mActivityInstance);
            mRewardedVideoAd.setRewardedVideoAdListener(mRewardedVideoListener);
        }
    });
    UiThread.exec();
}
 
Example 2
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 6 votes vote down vote up
@Override
protected Object __prepareRewardVideoAd(String adId) {
  // safety check to avoid exceptoin in case adId is null or empty
  if(adId==null || adId.length()==0) adId = TEST_REWARDVIDEO_ID;

  RewardedVideoAd ad = MobileAds.getRewardedVideoAdInstance(getActivity());
  ad.setRewardedVideoAdListener(new RewardVideoListener());

  synchronized (mLock) {
    if (!mIsRewardedVideoLoading) {
      mIsRewardedVideoLoading = true;
      Bundle extras = new Bundle();
      extras.putBoolean("_noRefresh", true);
      AdRequest adRequest = new AdRequest.Builder()
              .addNetworkExtrasBundle(AdMobAdapter.class, extras)
              .build();
      ad.loadAd(adId, adRequest);
    }
  }

  return ad;
}
 
Example 3
Source File: GenerateShortcutHelper.java    From TvAppRepo with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 4
Source File: MainActivity.java    From Instagram-Profile-Downloader with MIT License 4 votes vote down vote up
private void loadRewardedVideoAd() {


        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(MainActivity.this);
        mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
            @Override
            public void onRewardedVideoAdLoaded() {

            }

            @Override
            public void onRewardedVideoAdOpened() {
            }

            @Override
            public void onRewardedVideoStarted() {
            }

            @Override
            public void onRewardedVideoAdClosed() {
                closeApp();

            }

            @Override
            public void onRewarded(RewardItem rewardItem) {
            }

            @Override
            public void onRewardedVideoAdLeftApplication() {
            }

            @Override
            public void onRewardedVideoAdFailedToLoad(int i) {
                Log.e(TAG, "onRewardedVideoAdFailedToLoad: " + i);
            }

            @Override
            public void onRewardedVideoCompleted() {
                closeApp();
            }
        });

        mRewardedVideoAd.loadAd(getString(R.string.rewarded_video),
                new AdRequest.Builder()
//                        .addTestDevice("33BE2250B43518CCDA7DE426D04EE231")
                        .build());
    }
 
Example 5
Source File: AdMob.java    From capacitor-admob with MIT License 4 votes vote down vote up
@PluginMethod()
public void prepareRewardVideoAd(final PluginCall call) {
    this.call = call;
    /* dedicated test ad unit ID for Android rewarded video:
        ca-app-pub-3940256099942544/5224354917
    */
    final String adId = call.getString("adId", "ca-app-pub-3940256099942544/5224354917");

    try {
        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getContext());

        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mRewardedVideoAd.loadAd(adId, new AdRequest.Builder().build());


                mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
                    @Override
                    public void onRewardedVideoAdLoaded() {
                        call.success(new JSObject().put("value", true));
                        notifyListeners("onRewardedVideoAdLoaded", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoAdOpened() {
                        notifyListeners("onRewardedVideoAdOpened", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoStarted() {
                        notifyListeners("onRewardedVideoStarted", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoAdClosed() {
                        notifyListeners("onRewardedVideoAdClosed", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewarded(RewardItem rewardItem) {
                        notifyListeners("onRewarded", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoAdLeftApplication() {
                        notifyListeners("onRewardedVideoAdLeftApplication", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoAdFailedToLoad(int i) {
                        notifyListeners("onRewardedVideoAdFailedToLoad", new JSObject().put("value", true));
                    }

                    @Override
                    public void onRewardedVideoCompleted() {
                        notifyListeners("onRewardedVideoCompleted", new JSObject().put("value", true));
                    }
                });
            }
        });


    }catch (Exception ex) {
        call.error(ex.getLocalizedMessage(), ex);
    }

}
 
Example 6
Source File: ProfileFragment.java    From Android with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.profile_fragment, container, false);
    layout_settings = view.findViewById(R.id.layout_settings);
    layout1_editprofile = view.findViewById(R.id.layout1_editprofile);
    layout2_payment = view.findViewById(R.id.layout2_payment);
    layout_about = view.findViewById(R.id.layout_about);
    layout_share = view.findViewById(R.id.layout_share);
    layout_request = view.findViewById(R.id.layout_request);
    layout_redeem = view.findViewById(R.id.layout_redeem);

    more_points = view.findViewById(R.id.more_points);
    points_textview = view.findViewById(R.id.points);
    title = view.findViewById(R.id.title);

    mContext = this.getActivity();



    prefs = mContext.getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    ADMOB_PLEX_REWARDED_1 = prefs.getString("ADMOB_PLEX_REWARDED_1",null);
    user_id = prefs.getString("id",null);
    title.setText(prefs.getString("full_name","John Doe"));

    layout_settings.setOnClickListener(this);
    more_points.setOnClickListener(this);
    layout1_editprofile.setOnClickListener(this);
    layout2_payment.setOnClickListener(this);
    layout_about.setOnClickListener(this);
    layout_share.setOnClickListener(this);
    layout_request.setOnClickListener(this);
    layout_redeem.setOnClickListener(this);


    // Use an activity context to get the rewarded video instance.
    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(mContext);
    mRewardedVideoAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();
    update_points_value();
    get_points();
    return view;
}
 
Example 7
Source File: RewardedVideoAd.java    From admob-plus with MIT License 4 votes vote down vote up
private void createAndLoad(AdRequest adRequest) {
    clear();

    rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(plugin.cordova.getActivity());
    rewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
        @Override
        public void onRewardedVideoAdLoaded() {
            plugin.emit(getLoadedEvent());
        }

        @Override
        public void onRewardedVideoAdOpened() {
            plugin.emit(getOpenedEvent());
        }

        @Override
        public void onRewardedVideoStarted() {
            plugin.emit(Events.REWARD_VIDEO_START);
        }

        @Override
        public void onRewardedVideoAdClosed() {
            plugin.emit(getClosedEvent());
        }

        @Override
        public void onRewarded(RewardItem rewardItem) {
            plugin.emit(Events.REWARD_VIDEO_REWARD);
        }

        @Override
        public void onRewardedVideoAdLeftApplication() {
            plugin.emit(getLeftApplicationEvent());
        }

        @Override
        public void onRewardedVideoAdFailedToLoad(int errorCode) {
            plugin.emit(getFailedToLoadEvent(), buildErrorPayload(errorCode));
        }

        @Override
        public void onRewardedVideoCompleted() {
            plugin.emit(Events.REWARD_VIDEO_COMPLETE);
        }
    });
    rewardedVideoAd.loadAd(adUnitID, adRequest);
}
 
Example 8
Source File: AdMob.java    From GodotAds with Apache License 2.0 4 votes vote down vote up
public void createRewardedVideo() {
	mrv = MobileAds.getRewardedVideoAdInstance(activity);
	mrv.setRewardedVideoAdListener(new RewardedVideoAdListener() {

		@Override
		public void onRewardedVideoAdLoaded() {
			Utils.d("GodotAds", "AdMob:Video:Loaded");
			//emitRewardedVideoStatus();
			//Utils.call
			adRewardLoaded = true;
		}

		@Override
		public void onRewarded(RewardItem rewardItem) {
			Utils.d("GodotAds", "AdMob:Rewarded");

			JSONObject ret = new JSONObject();
			try {
				ret.put("RewardType", rewardItem.getType());
				ret.put("RewardAmount", rewardItem.getAmount());
			} catch (JSONException e) {
				Utils.d("GodotAds", "AdMob:Reward:Error:" + e.toString());
			}

			Utils.callScriptFunc("AdMob", "AdMobReward", ret.toString());
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoAdFailedToLoad(int errorCode) {
			Utils.d("GodotAds", "AdMob:VideoLoad:Failed");
			Utils.callScriptFunc("AdMob", "AdMob_Video", "load_failed");
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoAdClosed() {
			Utils.d("GodotAds", "AdMob:VideoAd:Closed");
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoAdLeftApplication() {
			Utils.d("GodotAds", "AdMob:VideoAd:LeftApp");
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoAdOpened() {
			Utils.d("GodotAds", "AdMon:VideoAd:Opended");
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoStarted() {
			Utils.d("GodotAds", "Reward:VideoAd:Started");
			adRewardLoaded = false;
		}

		@Override
		public void onRewardedVideoCompleted() {
			Utils.d("GodotAds", "Reward:VideoAd:Completed");
			adRewardLoaded = false;
			
			createRewardedVideo();
		}
	});

	requestNewRewardedVideo();
}
 
Example 9
Source File: GoogleRewardVideoAds.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@MainThread
private void loadNextVideo() {
	mCinemaRewardAd = MobileAds.getRewardedVideoAdInstance(Game.instance());
	mCinemaRewardAd.setRewardedVideoAdListener(new RewardVideoAdListener());
	mCinemaRewardAd.loadAd(Game.getVar(R.string.cinemaRewardAdUnitId), AdMob.makeAdRequest());
}