/mirrorworld-sdk-android

Mirror world market sdk demo on android platform

Primary LanguageJavaApache License 2.0Apache-2.0

Mirror World Android SDK

Mirror World's Official Android SDK

Getting started

Create a developer account on the Developer dashboard. Create project and create an API Key.

Import SDK

Notice:

The minimum version that SDK requires is Android 4.4.

  1. Download and uncompress Mirror World Android SDK.

  2. Put the mirrorsdk.aar under the 'libs' folder. You may create a 'libs' folder if it doesn't exist

  3. Add configeration to build.gradle:

dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
        }
  1. Config CustomTab! If you want to use CustomTab to show content to users (Recommended), you need to configure the following on your AndroidManifest.xml:

Add permission for internet

<uses-permission android:name="android.permission.INTERNET" />

Register this activity

<activity
    android:name="com.mirror.sdk.activities.RedirectActivity"
    android:exported="true">

    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="mwsdk"/>
    </intent-filter>
</activity>

Add dependency

implementation 'androidx.browser:browser:1.4.0'

You should now see CustomTab when you try to open our prepared web page.

Tips: If you want your app to have only one task, you can set your own activity to SingTast:

android:launchMode="singleTask"

Usage

Choose your chain

Developers must use specified classes to call APIs on specified chains.

There are two situations here: If you want to call an API from the Auth or Client module, simply type in "MirrorWorld." and the IDE will suggest all the APIs you may need. However, if you want to call an API on a specific chain, you will need to select the chain you want to work on after typing in "MirrorWorld.", and then choose the API you want from that chain's API. For example, if I want to buy an NFT on the Solana chain, I would need to type in MirrorWorld.Solana.Asset.buyNFT().

Each chain will include three functional modules: Asset, Wallet, and Metadata. If you are unsure where to find the specific API you want to call, you can refer to our API documentation.

Initialization

We can initialize Mirror World SDK with the following code:

Context context = this;
        String apiKey = "your-api-key";
        MirrorEnv env = MirrorEnv.DevNet;

        MirrorWorld.initSDK(context,apiKey,env);

Guide user to login

Users need to log in to use some MirrorSDK features (or APIs). If you want them to login for the first time or once again, use the following code:

MirrorWorld.startLogin(new LoginListener() {
@Override
public void onLoginSuccess() {
        Log.i("Mirror","User login success!");
        }

@Override
public void onLoginFail() {
        Log.i("Mirror","User login failed!");
        }
        });

But you may not want to let them login every time, so you can use CheckAuthenticated API to check if they have already logged in. According the result, you can show them a login button or hide your login button and make them enter your dApp or game directly.

MirrorWorld.isLoggedIn(new BoolListener() {
@Override
public void onBool(boolean boolValue) {
        Log.i("Mirror","This user's login state is:" + boolean);
        }
        });

Full API Documentation

You can view the documentation for Mirror World SDK for Mobile on our Official Documentation Site