65 lines
1.7 KiB
Java
65 lines
1.7 KiB
Java
package com.jc.jcfw;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.util.Log;
|
|
|
|
import com.fitchgc.headlesscocos.MainActivity;
|
|
|
|
import org.cocos2dx.lib.CocosJSHelper;
|
|
|
|
public class JcSDK {
|
|
private static final String TAG = JcSDK.class.getSimpleName();
|
|
private static UnityCallback commonCB;
|
|
public static void initCommonCB(UnityCallback callBack) {
|
|
Log.i(TAG, "call init common callback from unity");
|
|
commonCB = callBack;
|
|
}
|
|
|
|
/**
|
|
* @Deprecated
|
|
* 不使用该方法, 直接由unity调用cpp方法
|
|
* @param password
|
|
*/
|
|
public static void initWallet(String password) {
|
|
Log.i(TAG, "call init wallet from unity with password: " + password);
|
|
CocosJSHelper.initWallet(password);
|
|
commonCB.stringCallback("", "wallet init success");
|
|
}
|
|
|
|
/**
|
|
* 回调至c#
|
|
* @param funId
|
|
* @param msg
|
|
*/
|
|
public static void csCallback(String funId, String msg) {
|
|
if (!funId.equals("jscall")) {
|
|
commonCB.stringCallback(funId, msg);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* check if metamask installed and jump to metamask
|
|
* @param url
|
|
* sample: "https://metamask.app.link/wc?uri="+ExampleApplication.config.toWCUri();
|
|
*/
|
|
|
|
public static void toWallet(String url) {
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
Log.i(TAG, url);
|
|
try {
|
|
intent.setData(Uri.parse(url));
|
|
MainActivity.app.startActivity(intent);
|
|
} catch (ActivityNotFoundException e) {
|
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
i.setData(Uri.parse("https://metamask.io/download/"));
|
|
MainActivity.app.startActivity(i);
|
|
}
|
|
}
|
|
|
|
public static void scanQRCode(String funid, String title) {
|
|
MainActivity.app.showQRScan(funid, title);
|
|
}
|
|
}
|