# 초기화하기

Wepin widget android SDK를 초기화하는 방법입니다.&#x20;

먼저 위핀 인스턴스를 생성하고 앱 등록 후 할당 받은 앱 ID와 앱 키를 이용하여 인스턴스를 초기화 합니다.

## Wepin 인스턴스 생성하기&#x20;

위핀 위젯을 사용하고자 하는 앱의 activity에서 위핀 인스턴스를 먼저 생성 합니다. 인스턴스 생성시 위핀을 사용할 앱의 activity를 파라미터로 전달합니다. &#x20;

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

## 초기화하기

생성된 인스턴스를 사용하기 전에 앱  ID와 앱 키를 이용하여 초기화를 합니다.&#x20;

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

### WepinOptions

초기화에 사용되는 파라미터 <mark style="color:blue;">`WepinOptions`</mark> 클래스의 인터페이스는 아래와 같습니다.

```java
public class WepinOptions {
    String appId;  // 앱 아이디
    String appKey;  // 앱 키
    WidgetAttributes widgetAttributes;  // 위젯 속성 
}

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

* **appId**: *String*\
  앱 등록시 할당 받은 ID
* **appKey**: *String*\
  앱 등록시 할당 받은 키 값
* **attributes**: *Object (optional)*\
  위핀 위젯의 속성 값
  * **type**: *String*\
    처음 로딩 시 앱 위젯 윈도우를 어떻게 보여줄 지를 결정 합니다. 기본\
    값은 `hide` 입니다. \
    `show`: 처음 로딩 후, 바로 위젯 윈도우를 띄워서 보여 줍니다. \
    `hide`: 는 처음 로딩시 위젯 윈도우를 보여주지 않고 숨깁니다. 이후 `openWidget()`을 통해서 위젯을 띄워 보여 줍니다.
  * **defaultLanguage**: *String*\
    위젯 기본 언어 설정, 기본 값은 `ko`입니다. 현재 지원하는 언어는 `en`, `ko` 이렇게 2가지 입니다.
  * **defaultCurrency:** *String*\
    위젯 기본 통화 설정, 기본 값은 `KRW`입니다. 현재 지원하는 통화는 `USD`, `KRW` 이렇게 2가지 입니다.<br>

## isInitialized

<mark style="color:blue;">`isInitialized`</mark>메서드를 이용해서 Wepin 인스턴스가 정상적으로 초기화 되었는지 확인할 수 있습니다. &#x20;

반환값은 아래와 같습니다.&#x20;

* *boolean*\
  init 결괏값, init이 정상적으로 잘 된 경우 <mark style="color:orange;">`true`</mark> 실패한 경우 <mark style="color:orange;">`false`</mark> 를 반환합니다.

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

## 에러 리스너 등록하기

위핀 위젯에서 에러가 발생하는 경우 에러를 받아 처리하기 위한 에러 리스너를 구현하고 등록합니다. 에러 리스너를 반드시 등록할 필요는 없습니다. 필요에 따라서 선택이 가능합니다.&#x20;

파라미터로 위핀 위젯을 사용하는 앱의 activity에 구현할 수 있습니다.&#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);        
    }
}
```

## 예시

```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);
}
```


---

# 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.wepin.io/deprecated/android-java-and-kotlin-sdk/init.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.
