Sample project with example integration can be downloaded from: https://github.com/Nefta-io/NeftaSDK-Android:

Requirements

Minimal Android version 4.1 (API level 16)

Include the SDK

You can download the latest NeftaPlugin module from: https://github.com/Nefta-io/NeftaSDK-Android/releases.

Extract the NeftaPugin-release.aar file and include it in your Android project in /libs folder, so that it will look something like this:

Then include this module as a dependency in your project build.gradle:

implementation files('libs/NeftaPlugin-release.aar')

Permissions

For the SDK to work it requires permissions for the network which you need to add to your project AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Configuration

To serve and track the ads for your app, you have to configure ad units in the dashboard. There you will get the application ID for the next step.

Code integration

You initialize the SDK with the following code:

import com.nefta.sdk.NeftaPlugin;

NeftaPlugin plugin = NeftaPlugin.Init(getApplicationContext(), "yourAppId");

Do this as soon as possible in the application startup, to ensure the accurate event recording. If you leave the appId parameter null or empty the SDK will run in demo mode. This means that it'll always show dummy ads. To test the native integration without dashboard configuration.

If you want just the events this is all that is needed. You can proceed to the implementation of the actual events: https://docs-adnetwork.nefta.io/docs/integrate-nefta-game-events.

Code integration - Ads

To start the ad logic and retrieve all the configuration (so that no resources are wasted in case you are not having ads or you don't want them straight away):

_plugin.EnableAds(true);
_plugin.PrepareRenderer(this); // activity in which the ads will be rendered

Since the SDK doesn't want to introduce its own lifecycle dependencies, you need to call OnResume and OnPause methods when the app goes or comes from the background:

  @Override
  protected void onResume() {
     super.onResume();

     _plugin.OnResume();
  }

  @Override
  protected void onPause() {
     super.onPause();

     _plugin.OnPause();
  }

To know and react to SDK behavior, you can subscribe to the following callbacks:

_plugin.OnReady = this::OnReady;
_plugin.OnBid = this::OnBid;
_plugin.OnLoadStart = this::OnStartLoad;
_plugin.OnLoadFail = this::OnLoadFail;
_plugin.OnLoad = this::OnLoad;
_plugin.OnBannerChange = this::OnBannerChange;
_plugin.OnShow = this::OnShow;
_plugin.OnClick = this::OnClick;
_plugin.OnReward = this::OnReward;
_plugin.OnClose = this::OnClose;

Bidding

In case you have just one ad SDK or don't want to deal with header bidding you can skip this step.

The load function will bid and load an ad for you in the background.

You bid on a specific placement with this function:

_plugin.Bid("4922960754245632");
// or
_plugin.Bid(Placement.Types.Interstitial);

After which the OnBid callback will be fired with the price of the available ad or null if there is none. It is up to you to decide if you want to proceed and load this one, make another bid, go with an ad from another provider, or something else.

Loading and showing of an Ad

Before we can show an ad, we have to load it. We have two options for that. We can either load specific ad unit by its ID or type:

_plugin.Load("4922960754245632");
// or
_plugin.Load(Placement.Types.Interstitial);

After the ad loads the the OnLoad (or OnLoadFail) callback will be made. At that point IsReady function will start returning true:

_plugin.IsReady("4922960754245632");
// or
_plugin.IsReady(Placement.Types.Interstitial);

At this point, we can show the ad:

_plugin.Show("4922960754245632");
// or
_plugin.Show(Placement.Types.Interstitial);

Banner Ad Specifics

The easiest way to work with banners is to just toggle them on or off with the following function:

_plugin.EnableBanner(true);
// or
_plugin.EnableBanner("4922960754245632", true);

With this, the SDK will take care of the constant loading and showing banner placement to maximize your earnings from this position.

Whenever the banner presentation changes (gets shown, hidden, or changes size) you will get a OnBannerChange callback with covered width and height in physical pixel size so you can correctly offset application visual elements if needed.

Video Ad Specifics

After watching the rewarded video placement till the end, the OnReward will get fired so you can reward the player.

Miscellaneous

Nefta SDK is not managing audio settings, it is all under your control. So you will probably want to pause or mute your own sounds when showing Interstitial or rewarded video. And then resume or unmute after returning from the fullscreen ad, for example:

_plugin.OnShow = this::OnShow;
_plugin.OnClose = this::OnClose;

private void OnShow(Placement placement, int width, int height) {
   if (placement._type == Placement.Types.Interstitial || placement._type == Placement.Types.RewardedVideo) {
      _mediaPlayer.pause();
   }
}

private void OnClose(Placement placement) {
   if (placement._type == Placement.Types.Interstitial || placement._type == Placement.Types.RewardedVideo) {
      _mediaPlayer.start();
   }
}

Note that the ads are being rendered inside the Activity provided to PrepareRenderer. Therefore onPause and onResume won't be called when switching to and from Nefta Ads.

In case you want to set a custom identifier for the current player, which will be sent alongside BE calls:

_plugin.SetPublisherUserId("player23");

You can verify the correct SDK behavior through logs: Testing