Mirror World's Official Android SDK
Create a developer account on the Developer dashboard. Create project and create an API Key.
Notice:
The minimum version that SDK requires is Android 4.4.
-
Download and uncompress Mirror World Android SDK.
-
Put the
mirrorsdk.aar
under the 'libs' folder. You may create a 'libs' folder if it doesn't exist -
Add configeration to build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
}
- 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"
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.
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);
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);
}
});
You can view the documentation for Mirror World SDK for Mobile on our Official Documentation Site