> For the complete documentation index, see [llms.txt](https://docs.wepin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wepin.io/en/deprecated/android-java-and-kotlin-sdk/init.md).

# Initialization

Here is how to initialize the Wepin widget Android SDK.

First, create an instance of the Wepin widget. Then, use the App ID and App Key assigned after app registration to initialize the instance.

## Create Wepin Instance

In the activity of your app where you want to use the Wepin widget, first create an instance of Wepin. When creating the instance, pass the activity where you want to use Wepin as a parameter.

```java
wepin = Wepin.getInstance(MainActivity.this);
```

## Initialize

Before using the created instance, initialize it using the App ID and App Key.

```java
wepinOptions = new WepinOptions(appId, appKey, attributes);
wepin.initialize(widgetOptions);
```

### `WepinOptions`

The interface of the <mark style="color:blue;">`WepinOptions`</mark> class, which is used as a parameter for initialization, is as follows.

```java
public class WepinOptions {
    String appId;  // App ID
    String appKey;  // App Key
    WidgetAttributes widgetAttributes;  // Widget Attributes
}

public class WidgetAttributes {
    String type;
    String defaultLanguage;
    String defaultCurrency;
}
```

* **`appId`**: *String*\
  App ID assigned during registration
* **`appKey`**: *String*\
  App Key assigned during registration
* **`attributes`**: *Object (optional)*\
  Properties of the Wepin Widget
  * **`type`**: *String*\
    It determines how the app widget window will be displayed on initial loading. The default value is <mark style="color:blue;">`hide`</mark>. \
    `show`: Show the widget window immediately after loading for the first time.\
    `hide`: Hide the widget window initially when loading and show it later using <mark style="color:blue;">`openWidget()`</mark>.
  * **`defaultLanguage`**: *String*\
    The language to be displayed on the widget. The default value is <mark style="color:blue;">`ko`</mark>. The currently supported languages are <mark style="color:blue;">`en`</mark> and <mark style="color:blue;">`ko`</mark>.
  * **`defaultCurrency`:** *String*\
    The currency to be displayed on the widget. The default value is <mark style="color:blue;">`KRW`</mark>. The currently supported currencies are <mark style="color:blue;">`USD`</mark> and <mark style="color:blue;">`KRW`</mark>.<br>

## `isInitialized`

You can use the <mark style="color:blue;">`isInitialized`</mark> method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

* *boolean*\
  init result; <mark style="color:orange;">`true`</mark> if Wepin SDK is already initialized, otherwise <mark style="color:orange;">`false`</mark>.

```java
if(wepin.isInitialized()) {
    // Success to initialize wepin
}
```

## Register Error Listener

To handle errors that occur in the Wepin widget, implement an error listener and register it. It is not mandatory to register an error listener, as it is optional depending on your needs.

You can implement it in the activity of your app that uses the Wepin widget.&#x20;

```java
public class MainActivity extends AppCompatActivity implements WepinErrorListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //...
        Wepin wepin = Wepin.getInstance(MainActivity.this);
        wepin.setErrorListener(MainActivity.this);
    }
    // ... 
    @Override
    public void onWepinError(String errorMsg)
    {
        Log.d("onWepinError : " + errorMsg);        
    }
}
```

## Example

```java
Wepin wepin = Wepin.getInstance(MainActivity.this);
WidgetAttributes attributes = new WidgetAttributes("hide", "ko", "KRW");
WepinOptions wepinOptions = new WepinOptions(
    "app_id_eg12sf3491azgs520", 
    "ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313", 
    attributes
);

if(!wepin.isInitialized()) {
    wepin.initialize(widgetOptions);
}
```

##
