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.

wepin = Wepin.getInstance(MainActivity.this);

Initialize

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

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

WepinOptions

The interface of the WepinOptions class, which is used as a parameter for initialization, is as follows.

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 hide. 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 openWidget().

    • defaultLanguage: String The language to be displayed on the widget. The default value is ko. The currently supported languages are en and ko.

    • defaultCurrency: String The currency to be displayed on the widget. The default value is KRW. The currently supported currencies are USD and KRW.

isInitialized

You can use the isInitialized method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

  • boolean init result; true if Wepin SDK is already initialized, otherwise false.

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.

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

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

Last updated