From October 2020, Ogury released a new API specially refactored to improve the onboarding experience. In this guide, you will learn how to switch from the old API to the new one.
Import the Ogury SDK
In order to import the last version of the new Ogury SDK, you must update the Ogury's dependency in the build.gradle of your application. Now, you have to request the 5.+ version instead of the 4.+.
In the new API, the Ogury.start() must be called before you use the Ogury Choice Manager and the Thumbnail Ad (Native API)
Collect the consent
If you use the Ogury Choice Manager, you no longer have to initialize the Ogury's SDK in the OguryConsentListener callbacks. It must be initialized before calling the ask and edit method:
Old API
publicclassMyActivityextendsActivity { @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);OguryChoiceManager.initialize(context,"OGY-XXXXXXXXXXXX",newOguryCmConfig());OguryChoiceManager.ask(this, oguryConsentListener); }privatefinalOguryConsentListener oguryConsentListener =newOguryConsentListener() { @OverridepublicvoidonComplete(OguryChoiceManager.Answer answer) {Presage.getInstance().start("OGY-XXXXXXXXXXXX",this);// ... and load Ogury ad formats } @OverridepublicvoidonError(OguryError error) {Presage.getInstance().start("OGY-XXXXXXXXXXXX",this);// ... and load Ogury ad formats } };}
New API
publicclassMyActivityextendsActivity { @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(this, "OGY-XXXXXXXXXXXX");
Ogury.start(oguryConfigurationBuilder.build());OguryChoiceManager.ask(this, oguryConsentListener); }privatefinalOguryConsentListener oguryConsentListener =newOguryConsentListener() { @OverridepublicvoidonComplete(OguryChoiceManager.Answer answer) {// ... start other SDK - including AdMob's SDK - and load ad formats } @OverridepublicvoidonError(OguryError error) {// ... start other SDK - including AdMob's SDK - and load ad formats } };}
Note the OguryChoiceManager.initialize() method is not required anymore. It is replaced by the Ogury.start().
If you are still using the deprecated API of the Ogury Choice Manager, note the API has changed a bit:
The way Thumbnail ads (native API) is loaded and displayed has not really changed. Ogury has just refactored a little bit the API in order to have a more consistent and smother API. Let's take a look at the changes.
The constructor takes no longer take an Activity and an AdConfig object as parameters. Now, it takes aContext and an ad unit string.
The method used to register a listener on the lifecycle of the thumbnail ad is now setListener instead of setCallback and takes a OguryThumbnailAdListener object as parameters instead of a OguryThumbnailAdCallback.
the OguryThumbnailAdCallback object becomes OguryThumbnailAdListener and the methods to implement is now:
Methods
Definition
onAdLoaded
The SDK is ready to display the ad provided by the ad server.
onAdDisplayed
The ad has been displayed on the screen.
onAdClicked
The as has been clicked by the user.
onAdClosed
The ad has been closed by the user.
onAdError
The ad failed to load or display.
The onAdAvailable, onAdNotAvailable, onAdNotLoaded methods have been removed. The onAdNotAvailable, onAdNotLoaded callbacks are now replaced by the onAdError callback.
Now, the onAdError callback provides an OguryError object instead of an error code integer. The OguryError parameter contains the reason of the failure.