Checking for available videos

Using video mediation follows a 3-step process:

  1. Checking video availability
  2. Playing a video
  3. Rewarding the user

You can additionally:

Checking for available video

First, we check for available video. This should be done close to the point where the user will engage with a video. But not right before, as several ad network’s SDKs prefetch videos before they become available. And checking several networks for available video would take some time. Allow some time for the response to arrive.

  1. Make sure you’ve initialized the SDK previously as described in the Getting started with Fyber SDK guide.

  2. Make sure to have the following declaration in your AndroidManifest.xml. If you are using Gradle, you can skip this step:

     <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    
         [...]
    
         <uses-permission android:name="android.permission.INTERNET" />
         <application>
    
             [...]
    
             <activity
                 android:configChanges="screenSize|orientation"
                 android:name="com.fyber.ads.videos.RewardedVideoActivity"
                 android:hardwareAccelerated="true"/>
    
         </application>
    
     </manifest>
    
  3. Import the required packages:

     import com.fyber.requesters.RewardedVideoRequester;
    
  4. Add the requester snippet:

     RewardedVideoRequester.create(requestCallback)
         .request(context);
    
  5. You are then able to implement the RequestCallback interface, which defines the following methods:

     // RequestCallback interface implementation
    
     @Override
     public void onRequestError(RequestError requestError) {
         Log.d(TAG, "Something went wrong with the request: " + requestError.getDescription());
     }
    
     @Override
     public void onAdAvailable(Intent intent) {
         Log.d(TAG, "Ad is available");
         startActivityForResult(intent, REWARDED_VIDEO_REQUEST_CODE);
     }
    
     @Override
     public void onAdNotAvailable(AdFormat adFormat) {
         Log.d(TAG, "No ad available");
     }
    

Important: Do not request videos right after you initialize the SDK, because some of our mediation partners might still be caching videos at that point. This will result in a “no videos available” result, even though there are videos available. Choose a time instead close to the point where the user will engage with a video.

After you call .request(context);, the RequestCallback will be notified of the result.

Rewarding the User Using VCS

Let’s assume for this example that the same class which requests video offers implements the RequestCallback interface. The call would then look like this:

RewardedVideoRequester.create(this, requestCallback)
	.withVirtualCurrencyRequester(virtualCurrencyRequester)
	.request(context);

The virtualCurrencyRequester is an optional parameter which refers to an instance of VirtualCurrencyRequester. If an instance is passed as a parameter, a VCS query is performed after a successful video engagement.

To create a VirtualCurrencyRequester, we first need to define a VirtualCurrencyCallback.

VirtualCurrencyCallback virtualCurrencyCallback = new VirtualCurrencyCallback() {
    @Override
    public void onRequestError(RequestError requestError) {
        Log.d(TAG, "request error: " + requestError.getDescription());
    }

    @Override
    public void onSuccess(VirtualCurrencyResponse virtualCurrencyResponse) {
        // Process the deltaOfCoins in the way that makes most sense for your application
        double deltaOfCoins = virtualCurrencyResponse.getDeltaOfCoins();
    }

    @Override
    public void onError(VirtualCurrencyErrorResponse virtualCurrencyErrorResponse) {
        Log.d(TAG, "Virtual Currency Server error received - " + virtualCurrencyErrorResponse.getErrorMessage());
    }
};

Then you would create the VirtualCurrencyRequester:

VirtualCurrencyRequester virtualCurrencyRequester = VirtualCurrencyRequester.create(virtualCurrencyCallback);

As a last step in this context, you would then include the VirtualCurrencyRequester in the RewardedVideoRequester:

RewardedVideoRequester.create(requestCallback)
        .withVirtualCurrencyRequester(virtualCurrencyRequester)
        .request(activity);

When the request for offers is finished the appropriate method of the RequestCallback interface is then called. If an offer is available, you can store the received Intent to start it later or start it right away with the startActivityForResult method.

Note: Starting on SDK version 8.12.0, when attaching a VirtualCurrencyRequester to the RewardedVideoRequester instance, the Currency Id used will be the one set in the dashboard. Therefore, calls to .forCurrencyID(currencyId) will be ignored.

Toast Messages

When the Fyber SDK is first started, you receive a settings object that you can then use to customize the toast notifications. The Fyber SDK will show a toast notification by default (“Thanks! Your reward will be paid out shortly”) when a successful engagement is achieved.

If you want to disable it, you can call the following method to disable:

Fyber.Settings settings = Fyber.with(appId, this).start();
        settings.notifyUserOnCompletion(false)

You are also able to define the behavior by chaining .notifyUserOnCompetion(false) on your request:

  RewardedVideoRequester
                .create(this)
                .withVirtualCurrencyRequester(getVirtualCurrencyRequester())
                .notifyUserOnCompletion(false)
                .request(getActivity());

If you want to customize the rewarded notification default text, you should call settings.setCustomUIString(Fyber.Settings.UIStringIdentifier.RV_REWARD_NOTIFICATION, "NEW CUSTOM MESSAGE %.0f %s");

Adding Custom Parameters for Rewarded Video

If you are interested in adding a custom parameter to your Android SDK Interstitials request, you can pass along custom parameters in this way:

``` // creating a map of parameters to be used with a specific offer wall requester Map mapOfParameters = new HashMap<String,String>(); mapOfParameters.put(“pub1”, “value1”); mapOfParameters.put(“pub2”, “value2”);

RewardedVideoRequester rewardedVideoRequester = RewardedVideoRequester.create(callback); //adding a custom parameter to be used with this offer wall requester rewardedVideoRequester.addParameter(“pub3”, “value3”) //adding a list of custom parameters to be used in this offer wall requester .addParameters(mapOfParameters);