# SDK Initialization

### 🧑‍💻 Integration Guide

#### 1. Flutter Implementation

In your `main.dart` file:

```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  static const platform = MethodChannel('com.example.offerwall_app');

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('AdJump Example')),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              _launchOfferWall();
            },
            child: Text('Launch OfferWall'),
          ),
        ),
      ),
    );
  }

  Future<void> _launchOfferWall() async {
    try {
      final Map<String, String> params = {
        'accountId': 'YOUR_ACCOUNT_ID',
        'appId': 'YOUR_APP_ID',
        'userId': 'USER_ID',
      };
      await platform.invokeMethod('launchOfferWall', params);
    } on PlatformException catch (e) {
      print("Failed to show offer wall: '${e.message}'.");
    }
  }
}
```

#### 2. Android Implementation

In your `MainActivity.kt`:

```kotlin
package com.example.adjump

import android.widget.Toast
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.adjump.offerwall.AdJump

class MainActivity : FlutterActivity() {
    private val CHANNEL = "com.example.offerwall_app"
    private var adJump: AdJump? = null

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
            .setMethodCallHandler { call, result ->
                when (call.method) {
                    "launchOfferWall" -> {
                        val arguments = call.arguments as? Map<*, *>
                        if (arguments != null) {
                            val accountId = arguments["accountId"] as? String
                            val appId = arguments["appId"] as? String
                            val userId = arguments["userId"] as? String

                            if (accountId != null && appId != null && userId != null) {
                                adJump = AdJump(this, accountId, appId, userId)
                                launchOfferWall()
                                result.success("Offer wall launched")
                            } else {
                                result.error("INVALID_ARGUMENTS", "Missing required parameters", null)
                            }
                        } else {
                            result.error("INVALID_ARGUMENTS", "Arguments are required", null)
                        }
                    }
                    else -> result.notImplemented()
                }
            }
    }

    private fun launchOfferWall() {
        adJump?.initialize(object : AdJump.InitialisationListener {
            override fun onInitialisationSuccess() {
                runOnUiThread { Toast.makeText(this@MainActivity, "AdJump SDK Initialized", Toast.LENGTH_SHORT).show() }
                if (adJump?.isAvailable == true) {
                    adJump?.launchOfferWall()
                } else {
                    Toast.makeText(this@MainActivity, "Offerwall not available!", Toast.LENGTH_SHORT).show()
                }
            }

            override fun onInitialisationError(exception: Exception) {
                runOnUiThread { Toast.makeText(this@MainActivity, "Initialization failed: ${exception.message}", Toast.LENGTH_SHORT).show() }
            }
        })
    }
}
```

***

### 🔑 Configuration

1. Replace the placeholder values in your Flutter code with your actual Adjump credentials:
   * `YOUR_ACCOUNT_ID`: Your Adjump account identifier
   * `YOUR_APP_ID`: Your application identifier
   * `USER_ID`: The user identifier for the current session
2. Make sure the method channel name matches in both Flutter and Android code:

   ```dart
   static const platform = MethodChannel('com.example.offerwall_app');
   ```

***

### 🧪 Testing

* Make sure you're running on a physical Android device or emulator with internet access
* Log output and Toast messages will indicate:
  * SDK initialization status
  * Offerwall availability
  * Any errors that occur during the process

***

### ❓ FAQ

**Q: Does it support iOS?**\
A: No, this SDK currently supports Android only.

**Q: Where do I get my `accountId`, `appId`, and `userId`?**\
A: These are provided by the Adjump platform once you're onboarded.

**Q: What happens if the credentials are invalid?**\
A: The SDK will show an error message through a Toast notification and log the error details.

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.adjump.io/flutter/sdk-initialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
