Skip to main content

Getting Started

🚀 SDK Initialization

Before loading any ads, you must initialize the SDK. There are two initialization methods available:

✅ Option 1: initializeWithConfig() – Local Config

Use this if you want full control and local inline config via code.

Kotlin

val config = OcmConfigBuilder()
.adUnit(
id = "1001-sreq-test-300x250-imp-1",
format = "banner",
size = "300x250",
position = "bottom",
refresh = 30
)
.gam(
networkCode = "75351959",
adUnitPath = "/75351959/testadunit/test_app_320x50"
)
.privacyFromSdk(
gdpr = 0,
ccpa = "",
coppa = 0
)
.build()

lifecycleScope.launch {
OcmAdNetworkSDK.initializeWithConfig(
context = this@MainActivity,
config = config
) { result ->
result.onSuccess {
// SDK is ready to load ads
Log.d("AdNetworkSDK", "✅ SDK initialized")
}
result.onFailure {
Log.e("AdNetworkSDK", "❌ Initialization failed", it)
}
}
}

Java

OcmConfig config = new OcmConfigBuilder()
.adUnit(
"1001-sreq-test-300x250-imp-1",
"banner",
"300x250",
"bottom",
30
)
.gam(
"75351959",
"/75351959/testadunit/test_app_320x50"
)
.privacyFromSdk(
0, // gdpr
"", // ccpa
0 // coppa
)
.build();

OcmAdNetworkSDK.initializeWithConfigJava(
context,
config,
"20086", // for production, or "1001" for testing
() -> {
// SDK successfully initialized
Log.d("AdNetworkSDK", "✅ SDK initialized");
},
error -> {
Log.e("AdNetworkSDK", "❌ Init failed", error);
}
);

✅ Option 2: initialize() – With Config ID

Use this if your config is stored remotely or retrieved from backend.

Kotlin

lifecycleScope.launch {
OcmAdNetworkSDK.initialize(
context = this@MainActivity,
configId = "your-config-id"
) { result ->
result.onSuccess {
Log.d("AdNetworkSDK", "✅ SDK ready")
}
result.onFailure {
Log.e("AdNetworkSDK", "❌ Initialization failed", it)
}
}
}

Java

OcmAdNetworkSDK.initialize(
this,
"your-config-id",
() -> {
Log.d("AdNetworkSDK", "✅ SDK ready");
},
error -> {
Log.e("AdNetworkSDK", "❌ Init failed", error);
}
);

Quick Start Example

Here's a minimal example to get you started:

Kotlin

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

lifecycleScope.launch {
OcmAdNetworkSDK.initialize(
context = this@MainActivity,
configId = "your-config-id"
) { result ->
result.onSuccess {
Log.d("AdNetworkSDK", "✅ SDK initialized and ready to load ads")
}
result.onFailure {
Log.e("AdNetworkSDK", "❌ SDK init failed", it)
}
}
}
}
}

Java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

OcmAdNetworkSDK.initialize(
this,
"your-config-id",
() -> {
Log.d("AdNetworkSDK", "✅ SDK initialized and ready to load ads");
},
error -> {
Log.e("AdNetworkSDK", "❌ SDK init failed", error);
}
);
}
}

Best Practices

Initialize Early

Initialize the SDK as early as possible, ideally in your Application class or main Activity's onCreate() method.

Use Coroutines (Kotlin)

For Kotlin projects, use lifecycleScope or viewModelScope to handle initialization asynchronously:

lifecycleScope.launch {
// Initialize SDK here
}

Handle Errors

Always implement error handling to gracefully manage initialization failures:

result.onFailure { error ->
// Log error, show message to user, or retry
Log.e("AdNetworkSDK", "Failed to initialize", error)
}

Next Steps