package com.jc.jcfw; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; import android.util.Log; import com.cege.games.release.MainActivity; import org.cocos2dx.lib.CocosJSHelper; import org.json.JSONException; import org.json.JSONObject; public class JcSDK { private static final String TAG = JcSDK.class.getSimpleName(); private static UnityCallback commonCB; private static native int runJS(final String funId, final String methodName, final String params); 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.nativeCallback("", "wallet init success", 0); } /** * 回调至c# * @param funId * @param msg */ public static void csCallback(String funId, String msg) { if (funId != "" && funId.indexOf("js_") == 0) { commonCB.nativeCallback(funId, msg, 1); } else { commonCB.nativeCallback(funId, msg, 0); } } /** * 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); String downloadUrl = "https://metamask.io/download/"; if (url.startsWith("imtokenv2")) { downloadUrl = "https://token.im/download"; } i.setData(Uri.parse(downloadUrl)); MainActivity.app.startActivity(i); } } public static void showQRCode(String funid, String content) { MainActivity.app.showQRCode(funid, content, "", "");} public static void showRestoreQR(String funid, String content, String title, String oid) { MainActivity.app.showQRCode(funid, content, title, oid);} public static void scanQRCode(String funid, String title) { MainActivity.app.showQRScan(funid, title); } public static void loadRestoreKey(String funid, String oid) { MainActivity.app.loadRestoreKey(funid, oid); } public static void signWithTiktok(String funid) { MainActivity.app.signWithTiktok(funid); } public static void signWithFacebook(String funid) { MainActivity.app.signWithFacebook(funid); } public static void signWithTwitter(String funid) { MainActivity.app.signWithTwitter(funid); } public static void signWithGoogle(String funid) { MainActivity.app.signWithGoogle(funid); } public static void signOutGoogle(String funid) { MainActivity.app.signOutGoogle(funid); } public static void oauthCb(String funId, String error, String idToken) { JSONObject result = new JSONObject(); try { if (error != "" && null != error) { result.put("errcode", 1); result.put("errmessage", error); } else { result.put("errcode", 0); result.put("data", idToken); } } catch (JSONException e) { e.printStackTrace(); } if (null == funId || "".equals(funId)) { funId = MainActivity.app.getFunId(); } Log.i("TAG" ,result.toString()); String methodName = "jniCallback"; JcSDK.runJS(funId, methodName, result.toString()); } public static void scanQrCb(String funId, String error, String data) { JSONObject result = new JSONObject(); try { if (error != "" && null != error) { result.put("errcode", 1); result.put("errmessage", error); } else { result.put("errcode", 0); result.put("data", data); } } catch (JSONException e) { e.printStackTrace(); } String methodName = "jniCallback"; JcSDK.runJS(funId, methodName, result.toString()); } }