23个文件已修改
2个文件已删除
41个文件已添加
New file |
| | |
| | | //此脚本为渠道的第三方远程依赖库配置,会复制到unity中用于构建 |
| | | dependencies { |
| | | |
| | | } |
| | |
| | | <uses-permission android:name="android.permission.INTERNET" /> |
| | | |
| | | <application |
| | | android:name=".MyApp" |
| | | android:name="com.secondworld.sdk.BtGameApp" |
| | | android:allowBackup="true" |
| | | android:icon="@mipmap/ic_launcher" |
| | | android:label="@string/app_name" |
| | |
| | | import android.support.annotation.NonNull; |
| | | import android.widget.RelativeLayout; |
| | | |
| | | import com.secondworld.sdk.BtGameMain; |
| | | import com.secondworld.sdk.GameActivityProxy; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | |
| | | |
| | | public class MainActivity extends Activity { |
| | | |
| | | private static Class<? extends GameActivityProxy> proxyClass; |
| | | private static Class<? extends GameActivityProxy> proxyClass= BtGameMain.class; |
| | | |
| | | GameActivityProxy proxy; |
| | | |
| | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | GameAppProxy.isDemo=true; |
| | | setContentView(R.layout.activity_main); |
| | | RelativeLayout webContainer = findViewById(com.secondworld.sdk.R.id.webContainer); |
| | | WebViewUtil.I.init(this, webContainer); |
| | |
| | | findViewById(R.id.pay).setOnClickListener((v -> { |
| | | JSONObject json = new JSONObject(); |
| | | try { |
| | | json.put("sid","10"); |
| | | json.put("serverName","bt2server"); |
| | | json.put("roleName","hahaha"); |
| | | json.put("roleID","123"); |
| | | json.put("money","110"); |
| | | json.put("vipLevel","5"); |
| | | json.put("level","10"); |
| | | json.put("familyName","hengha"); |
| | | json.put("createTime",""); |
| | | |
| | | json.put("code", CodeU2A.PlatformPay); |
| | | json.put("cpInfo", "com.sanxiagame.zmjgp099"); |
| | | json.put("orderId", System.currentTimeMillis() / 1000 + ""); |
| | | json.put("sid", "1"); |
| | | json.put("roleID", "test_role"); |
| | | json.put("title", "goods_100"); |
| | | json.put("mount", "0.01"); |
| | | json.put("mount", "0.009999999776482582"); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | }); |
| | | |
| | | findViewById(R.id.btnB).setOnClickListener(v -> { |
| | | unityMessage(CodeU2A.ShareToFaceBook); |
| | | JSONObject json = new JSONObject(); |
| | | try { |
| | | json.put("sid","bt2"); |
| | | json.put("serverName","bt2server"); |
| | | json.put("roleName","hahaha"); |
| | | json.put("roleID","123"); |
| | | json.put("money","110"); |
| | | json.put("vipLevel","5"); |
| | | json.put("level","10"); |
| | | json.put("familyName","hengha"); |
| | | json.put("createTime",""); |
| | | |
| | | json.put("code", CodeU2A.CreateRole); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | UnityMsgHandler.onUnityMessage(json.toString()); |
| | | }); |
| | | } |
| | | |
| | |
| | | package com.secondworld.demo; |
| | | |
| | | import com.secondworld.sdk.GTGameApp; |
| | | import com.secondworld.sdk.GTGameMain; |
| | | import android.app.Application; |
| | | |
| | | public class MyApp extends GTGameApp { |
| | | import com.secondworld.sdk.BtGameMain; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | |
| | | public class MyApp extends Application { |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | isDemo=true; |
| | | super.onCreate(); |
| | | } |
| | | |
| | | @Override |
| | | protected void registerProxy() { |
| | | super.registerProxy(); |
| | | GameAppProxy.create(this,null); |
| | | GameAppProxy.isDemo=true; |
| | | //主界面代理注册 |
| | | MainActivity.registerProxy(GTGameMain.class); |
| | | MainActivity.registerProxy(BtGameMain.class); |
| | | } |
| | | |
| | | } |
| | |
| | | case UNKNOWN: { |
| | | if (GTGameMain.I.activity != null) |
| | | init(GTGameMain.I.activity); |
| | | Toast.makeText(GameApp.I, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | break; |
| | | } |
| | | case SUCCEED: { |
| | |
| | | break; |
| | | } |
| | | case LOADING: { |
| | | Toast.makeText(GameApp.I, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void setListener() { |
| | | args = new HashMap<>(); |
| | | // 初始化监听 |
| | | SdkManager.getInstance().setInitListener(new InitListener() { |
| | | @Override |
| | |
| | | info.put("game_id", SdkManager.getInstance().getGameId()); |
| | | info.put("session_id", SdkManager.getInstance().getSessionId()); |
| | | args.put("info", info); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginOk,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginOk, args); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | LogUtil.e("SdkManager 登录成功", e); |
| | |
| | | LogUtil.e("SdkManager", "注册成功" + " isNewReg:" + isNewReg + " type:" + reg_type); |
| | | args.clear(); |
| | | args.put("reg_type", reg_type); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformRegisterOk,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformRegisterOk, args); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void onSuccess(String status, String orderId) { |
| | | LogUtil.debug("SdkManager", "onSuccess status:" + status + ",orderId:" + orderId); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onError() { |
| | | LogUtil.e("SdkManager", "onError"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayFail); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | LogUtil.debug("SdkManager", "onCancel"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayCancel); |
| | | } |
| | | }); |
| | | |
| | |
| | | public void onSuccess(String type) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Success); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", "onSuccess:" + type); |
| | | } |
| | | |
| | |
| | | public void onError(String type, String msg) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Error); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", "type:" + type + ";msg:" + msg); |
| | | } |
| | | |
| | |
| | | public void onCancel(String type) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Cancel); |
| | | UnityMsgHandler.sendMessageToUnity( CodeA2U.ShareState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", type + ":onCancel"); |
| | | } |
| | | }); |
| | |
| | | public void onSuccess() { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Success); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "成功"); |
| | | } |
| | | |
| | |
| | | public void onError(String s) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Error); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "失败:" + s); |
| | | } |
| | | |
| | |
| | | public void onCancel() { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Cancel); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState,args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "取消"); |
| | | } |
| | | }); |
| | |
| | | import android.util.Base64; |
| | | |
| | | import com.cy.yyjia.sdk.center.SdkManager; |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | JSONObject extraData = new JSONObject(); |
| | | extraData.put("appid", GameApp.I.appId); |
| | | extraData.put("appid", GameAppProxy.appId); |
| | | extraData.put("cpinfo", json.getString("cpInfo")); |
| | | extraData.put("cporderid", json.getString("orderId")); |
| | | byte[] bytes = extraData.toString().getBytes(StandardCharsets.UTF_8); |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | public class GTGameApp extends GameApp { |
| | | import android.app.Application; |
| | | |
| | | public class GTGameApp extends Application { |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | GameAppProxy.create(this,new GTGamePlatform()); |
| | | registerProxy(); |
| | | initSdk(); |
| | | } |
| | | |
| | | protected void registerProxy() { |
| | | super.registerProxy(); |
| | | //主界面代理注册 |
| | | GameActivity.registerProxy(GTGameMain.class); |
| | | AppsFlyerUtil.init(); |
| | | } |
| | | |
| | | @Override |
| | | protected void initPlatformDiff() { |
| | | PlatformDiff.I = new GTGamePlatform(); |
| | | } |
| | | |
| | | @Override |
| | | protected void initSdk() { |
| | | super.initSdk(); |
| | | MySdkMgr.I.setListener(); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| | | xmlns:tools="http://schemas.android.com/tools" |
| | | package="com.secondworld.sdk"> |
| | | |
| | | <uses-permission android:name="android.permission.GET_TASKS" /> |
| | | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| | | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
| | | <uses-permission android:name="android.permission.INTERNET" /> |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| | | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
| | | <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> |
| | | <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> |
| | | |
| | | <application |
| | | android:name=".BtGameApp" |
| | | android:allowBackup="true" |
| | | android:requestLegacyExternalStorage="true" |
| | | android:usesCleartextTraffic="true" |
| | | tools:replace="android:name"> |
| | | |
| | | <meta-data |
| | | android:name="unityplayer.ForwardNativeEventsToDalvik" |
| | | android:value="true" /> |
| | | |
| | | <activity |
| | | android:name="com.secondworld.sdk.SplashActivity" |
| | | android:screenOrientation="sensorLandscape"> |
| | | </activity> |
| | | |
| | | <provider |
| | | android:name="android.support.v4.content.FileProvider" |
| | | android:authorities="quicksdk_packName.Provider" |
| | | android:exported="false" |
| | | android:grantUriPermissions="true"> |
| | | <meta-data |
| | | android:name="android.support.FILE_PROVIDER_PATHS" |
| | | android:resource="@xml/filepaths" /> |
| | | </provider> |
| | | |
| | | |
| | | </application> |
| | | |
| | | </manifest> |
New file |
| | |
| | | //当前脚本为渠道的差异化配置 |
| | | dependencies { |
| | | // implementation project(path: ':quick') |
| | | } |
New file |
| | |
| | | //此脚本为渠道的第三方远程依赖库配置,会复制到unity中用于构建 |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | public class BtGameApp extends QuickApp { |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | QuickSdkMgr.I.register("25969262062227241391437599980432","93995626"); |
| | | } |
| | | |
| | | @Override |
| | | protected PlatformDiff getPlatform() { |
| | | return new BtGamePlatform(); |
| | | } |
| | | |
| | | @Override |
| | | protected Class<? extends GameActivityProxy> getMainProxy() { |
| | | return BtGameMain.class; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.AlertDialog; |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.support.annotation.NonNull; |
| | | import android.view.KeyEvent; |
| | | |
| | | import com.quicksdk.QuickSDK; |
| | | import com.quicksdk.Sdk; |
| | | |
| | | public class BtGameMain extends GameActivityProxy { |
| | | |
| | | @Override |
| | | public void onCreate(Activity activity) { |
| | | super.onCreate(activity); |
| | | QuickSdkMgr.I.requestPermissions(activity); |
| | | com.quicksdk.Sdk.getInstance().onCreate(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onStart() { |
| | | super.onStart(); |
| | | com.quicksdk.Sdk.getInstance().onStart(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onRestart() { |
| | | super.onRestart(); |
| | | com.quicksdk.Sdk.getInstance().onRestart(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | com.quicksdk.Sdk.getInstance().onResume(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onStop() { |
| | | super.onStop(); |
| | | com.quicksdk.Sdk.getInstance().onStop(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy() { |
| | | super.onDestroy(); |
| | | com.quicksdk.Sdk.getInstance().onDestroy(activity); |
| | | } |
| | | |
| | | @Override |
| | | public void onNewIntent(Intent intent) { |
| | | super.onNewIntent(intent); |
| | | com.quicksdk.Sdk.getInstance().onNewIntent(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | super.onActivityResult(requestCode, resultCode, data); |
| | | QuickSdkMgr.I.onActivityResult(activity, requestCode); |
| | | com.quicksdk.Sdk.getInstance().onActivityResult(activity, requestCode, resultCode, data); |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | QuickSdkMgr.I.onRequestPermissionsResult(activity, requestCode, grantResults); |
| | | } |
| | | |
| | | @Override |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| | | if (QuickSDK.getInstance().isShowExitDialog()) { |
| | | Sdk.getInstance().exit(activity); |
| | | } else { |
| | | // 游戏调用自身的退出对话框,点击确定后,调用quick的exit接口 |
| | | new AlertDialog.Builder(activity).setTitle("退出").setMessage("是否退出游戏?").setPositiveButton("确定", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface arg0, int arg1) { |
| | | Sdk.getInstance().exit(activity); |
| | | } |
| | | }).setNegativeButton("取消", null).show(); |
| | | } |
| | | return true; |
| | | } |
| | | return super.onKeyDown(keyCode, event); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | public class BtGamePlatform extends PlatformDiff { |
| | | |
| | | @Override |
| | | public String platformName() { |
| | | return "sanxia"; |
| | | } |
| | | } |
| | |
| | | ## Automatically convert third-party libraries to use AndroidX |
| | | android.enableJetifier=false |
| | | #当前构建的渠道名称 |
| | | CHANNEL_NAME=gtgame |
| | | CHANNEL_NAME=qkbt2game |
| | |
| | | // implementation 'com.github.pqpo:Log4a:1.4.2@aar' |
| | | |
| | | implementation fileTree(dir: "../channel/${CHANNEL_NAME}/libs/", include: ['*.jar']) |
| | | plugins.each { |
| | | implementation fileTree(dir: "${rootPath}/plugins/${it}/libs/", include: ['*.jar']) |
| | | } |
| | | implementation fileTree(dir: 'libs', include: ['*.jar'], exclude: ['unity-classes.jar']) |
| | | compileOnly files('libs/unity-classes.jar') |
| | | } |
| | |
| | | <uses-permission android:name="android.permission.RECORD_AUDIO" /> |
| | | |
| | | <application |
| | | android:name="com.secondworld.sdk.GameApp" |
| | | android:allowBackup="true" |
| | | android:supportsRtl="true"> |
| | | |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.view.KeyEvent; |
| | | import android.webkit.WebView; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.RelativeLayout; |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void onRestart() { |
| | | super.onRestart(); |
| | | if (proxy != null) |
| | | proxy.onRestart(); |
| | | } |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | if (proxy != null) |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void onNewIntent(Intent intent) { |
| | | super.onNewIntent(intent); |
| | | if (proxy != null) |
| | | proxy.onNewIntent(intent); |
| | | } |
| | | |
| | | @Override |
| | | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | super.onActivityResult(requestCode, resultCode, data); |
| | | if (proxy != null) |
| | | proxy.onActivityResult(requestCode, resultCode, data); |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | if (proxy != null) |
| | | proxy.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | } |
| | | |
| | | @Override |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | if (proxy == null) |
| | | return super.onKeyDown(keyCode, event); |
| | | boolean b = proxy.onKeyDown(keyCode, event); |
| | | return b ? b : super.onKeyDown(keyCode, event); |
| | | } |
| | | } |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Intent; |
| | | import android.support.annotation.NonNull; |
| | | import android.view.KeyEvent; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class GameActivityProxy { |
| | | |
| | | protected Activity activity; |
| | | public Activity activity; |
| | | |
| | | public static GameActivityProxy I; |
| | | |
| | |
| | | } |
| | | |
| | | public void onStart() { |
| | | |
| | | } |
| | | |
| | | public void onRestart() { |
| | | |
| | | } |
| | | |
| | |
| | | I = null; |
| | | } |
| | | |
| | | public void onNewIntent(Intent intent) { |
| | | } |
| | | |
| | | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | |
| | | } |
| | | |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | PermissionManager.I.onRequestPermissionsResult(activity,requestCode, permissions, grantResults); |
| | | PermissionManager.I.onRequestPermissionsResult(activity, requestCode, permissions, grantResults); |
| | | } |
| | | |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | return false; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import android.app.Application; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Handler; |
| | | |
| | | import com.unity3d.player.UnityPlayer; |
| | | |
| | | public class GameAppProxy { |
| | | |
| | | public static Application app; |
| | | |
| | | public static String appId = ""; |
| | | |
| | | public static boolean isDemo = false; |
| | | |
| | | public static void create(Application app, PlatformDiff diff) { |
| | | PlatformDiff.I = diff; |
| | | GameAppProxy.app = app; |
| | | UnityMsgHandler.initCommandMap(); |
| | | } |
| | | |
| | | public static void appExit() { |
| | | new Handler().postDelayed(() -> { |
| | | android.os.Process.killProcess(android.os.Process.myPid());// 杀进程 |
| | | }, 1000); |
| | | if (UnityPlayer.currentActivity != null) |
| | | UnityPlayer.currentActivity.finish(); |
| | | } |
| | | |
| | | public static void restartApp() { |
| | | new Handler().postDelayed(() -> { |
| | | String _pn = app.getPackageName(); |
| | | PackageManager packageManager = app.getPackageManager(); |
| | | Intent intent = packageManager.getLaunchIntentForPackage(_pn); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | app.startActivity(intent); |
| | | android.os.Process.killProcess(android.os.Process.myPid());// 杀进程 |
| | | }, 1000); |
| | | if (UnityPlayer.currentActivity != null) |
| | | UnityPlayer.currentActivity.finish(); |
| | | } |
| | | |
| | | //是否位demo |
| | | public static boolean isDemo() { |
| | | return isDemo; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.secondworld.sdk.utils.CallBackState; |
| | | import com.secondworld.sdk.utils.CodeA2U; |
| | | import com.secondworld.sdk.utils.RequestCode; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | |
| | | public static PermissionManager I = new PermissionManager(); |
| | | |
| | | private static final int REQUEST_CODE = 9527; |
| | | |
| | | /** |
| | | * 查询是否有权限 |
| | | */ |
| | | public boolean hasPermission(String permission) { |
| | | return ContextCompat.checkSelfPermission(GameApp.I, permission) == PackageManager.PERMISSION_GRANTED |
| | | && PermissionChecker.checkSelfPermission(GameApp.I, permission) == PackageManager.PERMISSION_GRANTED; |
| | | return ContextCompat.checkSelfPermission(GameAppProxy.app, permission) == PackageManager.PERMISSION_GRANTED |
| | | && PermissionChecker.checkSelfPermission(GameAppProxy.app, permission) == PackageManager.PERMISSION_GRANTED; |
| | | } |
| | | |
| | | /** |
| | |
| | | public void requestPermissions(String permission) { |
| | | if (GameActivityProxy.I == null || GameActivityProxy.I.activity == null) |
| | | return; |
| | | ActivityCompat.requestPermissions(GameActivityProxy.I.activity, new String[]{permission}, REQUEST_CODE); |
| | | ActivityCompat.requestPermissions(GameActivityProxy.I.activity, new String[]{permission}, RequestCode.UNITY); |
| | | } |
| | | |
| | | |
| | | public void onRequestPermissionsResult(Activity activity, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | if (activity == null||permissions.length==0||requestCode!=REQUEST_CODE) |
| | | if (activity == null || permissions.length == 0 || requestCode != RequestCode.UNITY) |
| | | return; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("permission",permissions[0]); |
| | | map.put("permission", permissions[0]); |
| | | if (hasPermission(permissions[0])) { |
| | | map.put("state", CallBackState.Success); |
| | | } else { |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class PlatformSdkMgr { |
| | |
| | | LOADING//正在初始化 |
| | | } |
| | | |
| | | protected Map<String, Object> args; |
| | | protected Map<String, Object> args = new HashMap<>();; |
| | | |
| | | public SdkInitState sdkInitState = SdkInitState.UNKNOWN; //sdk初始化状态 |
| | | |
| | |
| | | |
| | | import com.secondworld.sdk.command.CmdInit; |
| | | import com.secondworld.sdk.command.ICommand; |
| | | import com.secondworld.sdk.utils.CodeA2U; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | | import com.secondworld.sdk.utils.StaticDefine; |
| | | import com.unity3d.player.UnityPlayer; |
| | |
| | | */ |
| | | public static List<String> getClassName(String packageName) throws IOException { |
| | | List<String> classNameList = new ArrayList<String>(); |
| | | DexFile df = new DexFile(GameApp.I.getPackageCodePath());//通过DexFile查找当前的APK中可执行文件 |
| | | DexFile df = new DexFile(GameAppProxy.app.getPackageCodePath());//通过DexFile查找当前的APK中可执行文件 |
| | | Enumeration<String> enumeration = df.entries();//获取df中的元素 这里包含了所有可执行的类名 该类名包含了包名+类名的方式 |
| | | while (enumeration.hasMoreElements()) {//遍历 |
| | | String className = (String) enumeration.nextElement(); |
| | |
| | | args = new HashMap<>(); |
| | | args.put("code", code); |
| | | JSONObject jsonObject = new JSONObject(args); |
| | | if (GameApp.I.isDemo()) { |
| | | if (GameAppProxy.isDemo()) { |
| | | LogUtil.debug("发送消息到unity", jsonObject.toString()); |
| | | return; |
| | | } |
| | |
| | | import android.content.ClipboardManager; |
| | | import android.content.Context; |
| | | |
| | | import com.secondworld.sdk.AsyncTaskOperator; |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdCopyContent implements ICommand { |
| | |
| | | public void process(JSONObject json) { |
| | | try { |
| | | String content = json.getString("content"); |
| | | ClipboardManager mgr = (ClipboardManager) GameApp.I.getSystemService( |
| | | ClipboardManager mgr = (ClipboardManager) GameAppProxy.app.getSystemService( |
| | | Context.CLIPBOARD_SERVICE); |
| | | ClipData data = ClipData.newPlainText("playerId", content); |
| | | mgr.setPrimaryClip(data); |
| | |
| | | |
| | | import android.app.AlertDialog; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.PlatformDiff; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | import com.secondworld.sdk.utils.CodeA2U; |
| | |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws JSONException { |
| | | GameApp.I.appId = json.getString("appID"); |
| | | GameAppProxy.appId = json.getString("appID"); |
| | | |
| | | long size = DeviceUtil.getTotalRAMSize() / 1024 / 1024; |
| | | LogUtil.debug("CmdInit", "内存:" + size + " mb"); |
| | |
| | | _builder.setCancelable(false); |
| | | _builder.setMessage("您的设备运行内存不满足要求,无法正常运行游戏"); |
| | | _builder.setPositiveButton("确定", (dialogInterface, i) -> { |
| | | GameApp.I.appExit(); |
| | | GameAppProxy.appExit(); |
| | | }); |
| | | _builder.show(); |
| | | return; |
| | |
| | | import android.net.Uri; |
| | | import android.widget.Toast; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | | |
| | |
| | | File file = new File(path); |
| | | if (!file.exists()) { |
| | | LogUtil.w("InstallApp", "文件不存在"); |
| | | Toast.makeText(GameApp.I, "找不安装文件", Toast.LENGTH_SHORT).show(); |
| | | Toast.makeText(GameAppProxy.app, "找不安装文件", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | Intent _intent = new Intent(Intent.ACTION_VIEW); |
| | | _intent.setDataAndType(Uri.fromFile(file), |
| | | "application/vnd.android.package-archive"); |
| | | _intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | GameApp.I.startActivity(_intent); |
| | | GameAppProxy.app.startActivity(_intent); |
| | | } catch (Exception e) { |
| | | LogUtil.e("CmdInstallAPK", e); |
| | | } |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | |
| | | |
| | | @Override |
| | | public void process(JSONObject json) { |
| | | GameApp.I.restartApp(); |
| | | GameAppProxy.restartApp(); |
| | | } |
| | | } |
| | |
| | | import android.content.IntentFilter; |
| | | import android.os.BatteryManager; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | public void start() { |
| | | m_BatteryBroadCastReceiver = new BatteryBroadCastReceiver(); |
| | | IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
| | | GameApp.I.registerReceiver(m_BatteryBroadCastReceiver, filter); |
| | | GameAppProxy.app.registerReceiver(m_BatteryBroadCastReceiver, filter); |
| | | } |
| | | |
| | | public void stop() { |
| | | if (m_BatteryBroadCastReceiver != null) { |
| | | try { |
| | | GameApp.I.unregisterReceiver(m_BatteryBroadCastReceiver); |
| | | GameAppProxy.app.unregisterReceiver(m_BatteryBroadCastReceiver); |
| | | m_BatteryBroadCastReceiver = null; |
| | | } catch (IllegalArgumentException e) { |
| | | if (!Objects.requireNonNull(e.getMessage()).contains("Receiver not registered")) { |
| | |
| | | import android.os.Build; |
| | | import android.provider.Settings; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | |
| | | import java.net.NetworkInterface; |
| | | import java.util.Enumeration; |
| | |
| | | public static long getVersionCode() { |
| | | long appVersionCode = 0; |
| | | try { |
| | | PackageInfo packageInfo = GameApp.I.getApplicationContext() |
| | | PackageInfo packageInfo = GameAppProxy.app.getApplicationContext() |
| | | .getPackageManager() |
| | | .getPackageInfo(GameApp.I.getPackageName(), 0); |
| | | .getPackageInfo(GameAppProxy.app.getPackageName(), 0); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
| | | appVersionCode = packageInfo.getLongVersionCode(); |
| | | } else { |
| | |
| | | public static String getVersionName() { |
| | | String appVersionName = ""; |
| | | try { |
| | | PackageInfo packageInfo = GameApp.I.getApplicationContext() |
| | | PackageInfo packageInfo = GameAppProxy.app.getApplicationContext() |
| | | .getPackageManager() |
| | | .getPackageInfo(GameApp.I.getPackageName(), 0); |
| | | .getPackageInfo(GameAppProxy.app.getPackageName(), 0); |
| | | appVersionName = packageInfo.versionName; |
| | | } catch (PackageManager.NameNotFoundException e) { |
| | | LogUtil.e("getAppVersionName", e); |
| | |
| | | * @return |
| | | */ |
| | | public static long getTotalRAMSize() { |
| | | ActivityManager manager = (ActivityManager) GameApp.I.getSystemService(Context.ACTIVITY_SERVICE); |
| | | ActivityManager manager = (ActivityManager) GameAppProxy.app.getSystemService(Context.ACTIVITY_SERVICE); |
| | | ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); |
| | | manager.getMemoryInfo(info); |
| | | return info.totalMem; |
| | | } |
| | | |
| | | public static String getAndroidId() { |
| | | String ANDROID_ID = Settings.System.getString(GameApp.I.getContentResolver(), Settings.System.ANDROID_ID); |
| | | String ANDROID_ID = Settings.System.getString(GameAppProxy.app.getContentResolver(), Settings.System.ANDROID_ID); |
| | | if (ANDROID_ID == null || ANDROID_ID.equals("9774d56d682e549c")) |
| | | return ""; |
| | | return ANDROID_ID; |
| | |
| | | break; |
| | | } |
| | | } else { |
| | | WifiManager wifi = (WifiManager) GameApp.I.getSystemService(Context.WIFI_SERVICE); |
| | | WifiManager wifi = (WifiManager) GameAppProxy.app.getSystemService(Context.WIFI_SERVICE); |
| | | if (wifi != null) { |
| | | WifiInfo wifiInfo = wifi.getConnectionInfo(); |
| | | if (wifiInfo != null) { |
| | |
| | | |
| | | import android.content.res.AssetManager; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | |
| | | import java.io.File; |
| | |
| | | return; |
| | | } |
| | | |
| | | String _dest = GameApp.I.getExternalFilesDir("").getAbsolutePath(); |
| | | AssetManager _assetMgr = GameApp.I.getAssets(); |
| | | String _dest = GameAppProxy.app.getExternalFilesDir("").getAbsolutePath(); |
| | | AssetManager _assetMgr = GameAppProxy.app.getAssets(); |
| | | try { |
| | | String[] _fileNames = _assetMgr.list("android"); |
| | | if (_fileNames != null) { |
| | |
| | | */ |
| | | public static void copyOneAsset(String fileName) { |
| | | String originalPath = "android" + File.separator + fileName; |
| | | String destPath = GameApp.I.getExternalFilesDir( |
| | | String destPath = GameAppProxy.app.getExternalFilesDir( |
| | | "").getAbsolutePath() + File.separator + fileName; |
| | | String _destDir = destPath.substring(0, destPath.lastIndexOf('/') + 1); |
| | | File _file = new File(_destDir); |
| | |
| | | boolean mkdir = _file.mkdir(); |
| | | } |
| | | try { |
| | | InputStream _is = GameApp.I.getAssets().open(originalPath); |
| | | InputStream _is = GameAppProxy.app.getAssets().open(originalPath); |
| | | FileOutputStream _fos = new FileOutputStream(new File(destPath)); |
| | | byte[] _buffer = new byte[1024]; |
| | | int _byteCount; |
| | |
| | | |
| | | public static void copy(String original, String dest) { |
| | | try { |
| | | String[] fileNames = GameApp.I.getAssets().list(original); |
| | | String[] fileNames = GameAppProxy.app.getAssets().list(original); |
| | | if (fileNames.length > 0) { |
| | | File dir = new File(dest); |
| | | String mkdir = dir.mkdir() ? "成功" : "失败"; |
| | |
| | | dest + File.separator + _fileName); |
| | | } |
| | | } else { |
| | | InputStream _is = GameApp.I.getAssets().open(original); |
| | | InputStream _is = GameAppProxy.app.getAssets().open(original); |
| | | FileOutputStream _fos = new FileOutputStream(new File(dest)); |
| | | byte[] _buffer = new byte[1024]; |
| | | int _byteCount; |
New file |
| | |
| | | package com.secondworld.sdk.utils; |
| | | |
| | | public interface RequestCode { |
| | | int UNITY=1000; |
| | | int QUICK = 1001; |
| | | } |
| | |
| | | import android.content.Context; |
| | | import android.content.SharedPreferences; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | |
| | | public class SPUtils { |
| | | |
| | |
| | | |
| | | public static SharedPreferences get() { |
| | | if (data == null) |
| | | data = GameApp.I.getSharedPreferences("data", Context.MODE_PRIVATE); |
| | | data = GameAppProxy.app.getSharedPreferences("data", Context.MODE_PRIVATE); |
| | | return data; |
| | | } |
| | | |
| | |
| | | } |
| | | }; |
| | | |
| | | AppsFlyerLib.getInstance().init(AF_DEV_KEY, conversionListener, GameApp.I); |
| | | AppsFlyerLib.getInstance().startTracking(GameApp.I); |
| | | AppsFlyerLib.getInstance().init(AF_DEV_KEY, conversionListener, GameAppProxy.app); |
| | | AppsFlyerLib.getInstance().startTracking(GameAppProxy.app); |
| | | } |
| | | |
| | | //统计事件 |
| | | public static void trackEvent(String eventName, Map<String, Object> eventValues) { |
| | | if (eventValues == null) |
| | | eventValues = new HashMap<>(); |
| | | AppsFlyerLib.getInstance().trackEvent(GameApp.I, eventName, eventValues); |
| | | AppsFlyerLib.getInstance().trackEvent(GameAppProxy.app, eventName, eventValues); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | dependencies { |
| | | |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import com.quicksdk.QuickSdkApplication; |
| | | |
| | | public abstract class QuickApp extends QuickSdkApplication { |
| | | |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | GameAppProxy.create(this, getPlatform()); |
| | | GameActivity.registerProxy(getMainProxy()); |
| | | } |
| | | |
| | | protected abstract PlatformDiff getPlatform(); |
| | | |
| | | protected abstract Class<? extends GameActivityProxy> getMainProxy(); |
| | | |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | |
| | | import android.Manifest; |
| | | import android.app.Activity; |
| | | import android.app.AlertDialog; |
| | | import android.content.DialogInterface; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.net.Uri; |
| | | import android.provider.Settings; |
| | | import android.support.v4.app.ActivityCompat; |
| | | import android.support.v4.content.ContextCompat; |
| | | import android.widget.Toast; |
| | | |
| | | import com.quicksdk.BaseCallBack; |
| | | import com.quicksdk.Extend; |
| | | import com.quicksdk.FuncType; |
| | | import com.quicksdk.Payment; |
| | | import com.quicksdk.QuickSDK; |
| | | import com.quicksdk.Sdk; |
| | | import com.quicksdk.User; |
| | | import com.quicksdk.entity.GameRoleInfo; |
| | | import com.quicksdk.entity.OrderInfo; |
| | | import com.quicksdk.entity.UserInfo; |
| | | import com.quicksdk.notifier.ExitNotifier; |
| | | import com.quicksdk.notifier.InitNotifier; |
| | | import com.quicksdk.notifier.LoginNotifier; |
| | | import com.quicksdk.notifier.LogoutNotifier; |
| | | import com.quicksdk.notifier.PayNotifier; |
| | | import com.quicksdk.notifier.SwitchAccountNotifier; |
| | | import com.secondworld.sdk.utils.CodeA2U; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | | import com.secondworld.sdk.utils.RequestCode; |
| | | import com.unity3d.player.UnityPlayer; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | public class QuickSdkMgr extends PlatformSdkMgr { |
| | | |
| | | public static QuickSdkMgr I = new QuickSdkMgr(); |
| | | |
| | | String productCode; |
| | | String productKey; |
| | | |
| | | int REQUEST_RECORD_PERMISSION_SETTING = 110; |
| | | |
| | | private boolean hasPermissions(Activity activity) { |
| | | return (ContextCompat.checkSelfPermission(activity, |
| | | Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) |
| | | && (ContextCompat.checkSelfPermission(activity, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); |
| | | } |
| | | |
| | | public void requestPermissions(Activity activity) { |
| | | try { |
| | | // check权限 |
| | | if (!hasPermissions(activity)) { |
| | | // 没有则申请权限 |
| | | ActivityCompat.requestPermissions(activity, new String[]{ |
| | | Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCode.QUICK); |
| | | } else { |
| | | QuickSdkMgr.I.init(activity); |
| | | } |
| | | } catch (Exception e) { |
| | | QuickSdkMgr.I.init(activity); |
| | | } |
| | | } |
| | | |
| | | public void onRequestPermissionsResult(Activity activity, int requestCode, int[] grantResults) { |
| | | if (requestCode != RequestCode.QUICK) return; |
| | | if (hasPermissions(activity)) { |
| | | QuickSdkMgr.I.init(activity); |
| | | return; |
| | | } |
| | | final AlertDialog.Builder normalDialog = new AlertDialog.Builder(activity); |
| | | normalDialog.setTitle("权限设置"); |
| | | normalDialog.setMessage("游戏需要部分权限才能正常运行,请前往设置中打开电话权限与存储权限"); |
| | | normalDialog.setPositiveButton("前往设置", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| | | Uri uri = Uri.fromParts("package", activity.getPackageName(), null); |
| | | intent.setData(uri); |
| | | activity.startActivityForResult(intent, REQUEST_RECORD_PERMISSION_SETTING); |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | normalDialog.setNegativeButton("退出", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | GameAppProxy.appExit(); |
| | | } |
| | | }); |
| | | // 显示 |
| | | normalDialog.show(); |
| | | } |
| | | |
| | | public void onActivityResult(Activity activity, int requestCode) { |
| | | if (requestCode == REQUEST_RECORD_PERMISSION_SETTING) |
| | | requestPermissions(activity); |
| | | } |
| | | |
| | | public void init(Activity activity) { |
| | | sdkInitState = SdkInitState.LOADING; |
| | | Sdk.getInstance().init(activity, productCode, productKey); |
| | | } |
| | | |
| | | public void login() { |
| | | switch (sdkInitState) { |
| | | case FAILED: |
| | | case UNKNOWN: { |
| | | if (GameActivityProxy.I.activity == null) |
| | | return; |
| | | if (hasPermissions(GameActivityProxy.I.activity)) { |
| | | init(BtGameMain.I.activity); |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | } |
| | | break; |
| | | } |
| | | case SUCCEED: { |
| | | User.getInstance().login(GameActivityProxy.I.activity); |
| | | break; |
| | | } |
| | | case LOADING: { |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void loginOut() { |
| | | if (GameActivityProxy.I.activity == null) |
| | | return; |
| | | User.getInstance().logout(GameActivityProxy.I.activity); |
| | | } |
| | | |
| | | public void setGameRoleInfo(GameRoleInfo roleInfo, boolean createRole) { |
| | | if (GameActivityProxy.I.activity == null) |
| | | return; |
| | | User.getInstance().setGameRoleInfo(GameActivityProxy.I.activity, roleInfo, createRole); |
| | | } |
| | | |
| | | public void pay(OrderInfo orderInfo, GameRoleInfo roleInfo) { |
| | | if (GameActivityProxy.I.activity == null) |
| | | return; |
| | | Payment.getInstance().pay(GameActivityProxy.I.activity, orderInfo, roleInfo); |
| | | } |
| | | |
| | | public void verifyRealName() { |
| | | if (GameActivityProxy.I.activity == null) |
| | | return; |
| | | // 判断渠道是否支持实名认证功能 |
| | | if (Extend.getInstance().isFunctionSupported(FuncType.REAL_NAME_REGISTER)) { |
| | | Extend.getInstance().callFunctionWithParamsCallBack(GameActivityProxy.I.activity, FuncType.REAL_NAME_REGISTER, new BaseCallBack() { |
| | | @Override |
| | | public void onSuccess(Object... arg0) { |
| | | if (arg0 != null && arg0.length > 0) { |
| | | JSONObject jsonObject = (JSONObject) arg0[0]; |
| | | try { |
| | | // 用户id |
| | | String uid = jsonObject.getString("uid"); |
| | | // 年龄, 如果渠道没返回默认为-1 |
| | | int age = jsonObject.getInt("age"); |
| | | // 是否已实名 true表示已实名 |
| | | // false表示未实名,如果渠道没返回默认为false |
| | | boolean realName = jsonObject.getBoolean("realName"); |
| | | // oppo实名认证失败之后是否可以继续游戏 true表示可以 |
| | | // false表示不可以,如果渠道没返回默认为true |
| | | boolean resumeGame = jsonObject.getBoolean("resumeGame"); |
| | | // 预留字段,如果渠道没返回默认为""的字符串 |
| | | String other = jsonObject.getString("other"); |
| | | // 游戏根据返回信息做对应的逻辑处理 |
| | | |
| | | } catch (JSONException e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(Object... arg0) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | public void register(String productCode, String productKey) { |
| | | this.productCode = productCode; |
| | | this.productKey = productKey; |
| | | QuickSDK.getInstance().setInitNotifier(new InitNotifier() { |
| | | @Override |
| | | public void onSuccess() { |
| | | //初始化成功 |
| | | sdkInitState = SdkInitState.SUCCEED; |
| | | LogUtil.debug("SdkManager", "初始化成功"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String message, String trace) { |
| | | //初始化失败 |
| | | sdkInitState = SdkInitState.FAILED; |
| | | LogUtil.e("SdkManager", "初始化失败 msg:" + message); |
| | | LogUtil.e("SdkManager", "初始化失败 trace:" + trace); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitFail); |
| | | } |
| | | }); |
| | | QuickSDK.getInstance().setLoginNotifier(new LoginNotifier() { |
| | | @Override |
| | | public void onSuccess(UserInfo userInfo) { |
| | | //登录成功,获取到用户信息userInfo |
| | | //通过userInfo中的UID、token做服务器登录认证 |
| | | LogUtil.e("SdkManager", "登录成功"); |
| | | try { |
| | | args.clear(); |
| | | JSONObject info = new JSONObject(); |
| | | String cid = com.quicksdk.Extend.getInstance().getExtrasConfig("cid"); |
| | | if (cid == null || cid.isEmpty()) |
| | | cid = com.quicksdk.Extend.getInstance().getChannelType() + ""; |
| | | String account = userInfo.getUID() + "@" + cid; |
| | | info.put("account", account); |
| | | info.put("userName", userInfo.getUID()); |
| | | info.put("token", userInfo.getToken()); |
| | | args.put("info", info); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginOk, args); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | LogUtil.e("SdkManager 登录成功", e); |
| | | } |
| | | verifyRealName(); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | //登录取消 |
| | | LogUtil.e("SdkManager", "登录失败:"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginFail); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(final String message, String trace) { |
| | | //登录失败 |
| | | LogUtil.e("SdkManager", "登录失败:"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginFail); |
| | | } |
| | | }); |
| | | QuickSDK.getInstance().setLogoutNotifier(new LogoutNotifier() { |
| | | @Override |
| | | public void onSuccess() { |
| | | //注销成功 |
| | | //注销成功,需要把游戏切换回登陆前的场景,并重新弹出登录框等操作 |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLogoutOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String message, String trace) { |
| | | //注销失败,不做处理 |
| | | } |
| | | }); |
| | | QuickSDK.getInstance().setSwitchAccountNotifier(new SwitchAccountNotifier() { |
| | | @Override |
| | | public void onSuccess(UserInfo userInfo) { |
| | | //切换账号成功的回调,返回新账号的userInfo |
| | | LogUtil.e("SdkManager", "切换账号成功"); |
| | | try { |
| | | args.clear(); |
| | | JSONObject info = new JSONObject(); |
| | | String cid = com.quicksdk.Extend.getInstance().getExtrasConfig("cid"); |
| | | if (cid == null || cid.isEmpty()) |
| | | cid = com.quicksdk.Extend.getInstance().getChannelType() + ""; |
| | | String account = userInfo.getUID() + "@" + cid; |
| | | info.put("account", account); |
| | | info.put("userName", userInfo.getUID()); |
| | | info.put("token", userInfo.getToken()); |
| | | args.put("info", info); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformSwitchAccountOk, args); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | LogUtil.e("SdkManager 登录成功", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | //切换账号取消 |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String message, String trace) { |
| | | //切换账号失败 |
| | | } |
| | | }); |
| | | QuickSDK.getInstance().setPayNotifier(new PayNotifier() { |
| | | @Override |
| | | public void onSuccess(String sdkOrderID, String cpOrderID, |
| | | String extrasParams) { |
| | | //支付成功 |
| | | //sdkOrderID:quick订单号 cpOrderID:游戏订单号 |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel(String cpOrderID) { |
| | | //支付取消 |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayCancel); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String cpOrderID, String message, String trace) { |
| | | //支付失败 |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayFail); |
| | | } |
| | | }); |
| | | QuickSDK.getInstance().setExitNotifier(new ExitNotifier() { |
| | | @Override |
| | | public void onSuccess() { |
| | | //退出成功,游戏在此做自身的退出逻辑处理 |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ExitGame); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailed(String message, String trace) { |
| | | //退出失败,不做处理 |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk; |
| | | |
| | | import android.content.Intent; |
| | | import android.graphics.Color; |
| | | |
| | | import com.quicksdk.QuickSdkSplashActivity; |
| | | |
| | | public class SplashActivity extends QuickSdkSplashActivity { |
| | | |
| | | @Override |
| | | public int getBackgroundColor() { |
| | | return Color.WHITE; |
| | | } |
| | | |
| | | @Override |
| | | public void onSplashStop() { |
| | | Intent intent = new Intent(this, GameActivity.class); |
| | | startActivity(intent); |
| | | this.finish(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.quicksdk.entity.GameRoleInfo; |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdCreateRole implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.CreateRole; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | GameRoleInfo roleInfo = new GameRoleInfo(); |
| | | roleInfo.setServerID(json.getString("sid")); |
| | | roleInfo.setServerName(json.getString("serverName")); |
| | | roleInfo.setGameRoleName(json.getString("roleName").trim().replace(" ", "")); |
| | | roleInfo.setGameRoleID(json.getString("roleID")); |
| | | roleInfo.setGameBalance(json.getString("money")); |
| | | roleInfo.setVipLevel( json.getString("vipLevel")); //设置当前用户vip等级,必须为数字整型字符串,请勿传"vip1"等类似字符串 |
| | | roleInfo.setGameUserLevel(json.getString("level"));//设置游戏角色等级 |
| | | roleInfo.setPartyName(json.getString("familyName").trim().replace(" ",""));//设置帮派名称 |
| | | roleInfo.setRoleCreateTime( json.getString("createTime")); //UC,当乐与1881,TT渠道必传,值为10位数时间戳 |
| | | |
| | | roleInfo.setPartyId("1100"); //360渠道参数,设置帮派id,必须为整型字符串 |
| | | roleInfo.setGameRolePower("38"); //360,TT语音渠道参数,设置角色战力,必须为整型字符串 |
| | | roleInfo.setPartyRoleId("11"); //360渠道参数,设置角色在帮派中的id |
| | | roleInfo.setPartyRoleName("帮主"); //360渠道参数,设置角色在帮派中的名称 |
| | | roleInfo.setProfessionId("38"); //360渠道参数,设置角色职业id,必须为整型字符串 |
| | | roleInfo.setProfession("法师"); //360渠道参数,设置角色职业名称 |
| | | roleInfo.setFriendlist("无"); //360渠道参数,设置好友关系列表,格式请参考:http://open.quicksdk.net/help/detail/aid/190 |
| | | QuickSdkMgr.I.setGameRoleInfo(roleInfo, true); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdPayFinished implements ICommand{ |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.PayFinished; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdPlatformLogin implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.PlatformLogin; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | QuickSdkMgr.I.login(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdPlatformLogout implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.PlatformLogout; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | QuickSdkMgr.I.loginOut(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.quicksdk.entity.GameRoleInfo; |
| | | import com.quicksdk.entity.OrderInfo; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | import java.net.URLEncoder; |
| | | |
| | | public class CmdPlatformPay implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.PlatformPay; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | |
| | | |
| | | JSONObject extraData = new JSONObject(); |
| | | extraData.put("appid", GameAppProxy.appId); |
| | | extraData.put("cpinfo", json.getString("cpInfo")); |
| | | extraData.put("cporderid", json.getString("orderId")); |
| | | |
| | | GameRoleInfo roleInfo = new GameRoleInfo(); |
| | | roleInfo.setServerID(json.getString("sid")); |
| | | roleInfo.setServerName(json.getString("serverName")); |
| | | roleInfo.setGameRoleName(json.getString("roleName").trim().replace(" ", "")); |
| | | roleInfo.setGameRoleID(json.getString("roleID")); |
| | | roleInfo.setGameBalance(json.getString("money")); |
| | | roleInfo.setVipLevel(json.getString("vipLevel")); //设置当前用户vip等级,必须为数字整型字符串,请勿传"vip1"等类似字符串 |
| | | roleInfo.setGameUserLevel(json.getString("level"));//设置游戏角色等级 |
| | | roleInfo.setPartyName(json.getString("familyName").trim().replace(" ", ""));//设置帮派名称 |
| | | roleInfo.setRoleCreateTime(json.getString("createTime")); //UC,当乐与1881,TT渠道必传,值为10位数时间戳 |
| | | |
| | | roleInfo.setPartyId("1100"); //360渠道参数,设置帮派id,必须为整型字符串 |
| | | roleInfo.setGameRolePower("38"); //360,TT语音渠道参数,设置角色战力,必须为整型字符串 |
| | | roleInfo.setPartyRoleId("11"); //360渠道参数,设置角色在帮派中的id |
| | | roleInfo.setPartyRoleName("帮主"); //360渠道参数,设置角色在帮派中的名称 |
| | | roleInfo.setProfessionId("38"); //360渠道参数,设置角色职业id,必须为整型字符串 |
| | | roleInfo.setProfession("法师"); //360渠道参数,设置角色职业名称 |
| | | roleInfo.setFriendlist("无"); //360渠道参数,设置好友关系列表,格式请参考:http://open.quicksdk.net/help/detail/aid/190 |
| | | |
| | | |
| | | OrderInfo orderInfo = new OrderInfo(); |
| | | orderInfo.setCpOrderID(json.getString("orderId")); |
| | | orderInfo.setGoodsName(json.getString("title"));//商品名称,不带数量 |
| | | orderInfo.setCount(1);//游戏币数量 |
| | | orderInfo.setAmount((float) json.getDouble("mount")); |
| | | orderInfo.setGoodsID(json.getString("cpInfo")); |
| | | orderInfo.setGoodsDesc(json.getString("title")); |
| | | orderInfo.setExtrasParams( |
| | | URLEncoder.encode(extraData.toString(), "utf-8")); |
| | | |
| | | QuickSdkMgr.I.pay(orderInfo, roleInfo); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.quicksdk.entity.GameRoleInfo; |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdRoleLevelUp implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.RoleLevelUp; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | GameRoleInfo roleInfo = new GameRoleInfo(); |
| | | roleInfo.setServerID(json.getString("sid")); |
| | | roleInfo.setServerName(json.getString("serverName")); |
| | | roleInfo.setGameRoleName(json.getString("roleName").trim().replace(" ", "")); |
| | | roleInfo.setGameRoleID(json.getString("roleID")); |
| | | roleInfo.setGameBalance(json.getString("money")); |
| | | roleInfo.setVipLevel(json.getString("vipLevel")); //设置当前用户vip等级,必须为数字整型字符串,请勿传"vip1"等类似字符串 |
| | | roleInfo.setGameUserLevel(json.getString("level"));//设置游戏角色等级 |
| | | roleInfo.setPartyName(json.getString("familyName").trim().replace(" ", ""));//设置帮派名称 |
| | | roleInfo.setRoleCreateTime(json.getString("createTime")); //UC,当乐与1881,TT渠道必传,值为10位数时间戳 |
| | | |
| | | roleInfo.setPartyId("1100"); //360渠道参数,设置帮派id,必须为整型字符串 |
| | | roleInfo.setGameRolePower("38"); //360,TT语音渠道参数,设置角色战力,必须为整型字符串 |
| | | roleInfo.setPartyRoleId("11"); //360渠道参数,设置角色在帮派中的id |
| | | roleInfo.setPartyRoleName("帮主"); //360渠道参数,设置角色在帮派中的名称 |
| | | roleInfo.setProfessionId("38"); //360渠道参数,设置角色职业id,必须为整型字符串 |
| | | roleInfo.setProfession("法师"); //360渠道参数,设置角色职业名称 |
| | | roleInfo.setFriendlist("无"); //360渠道参数,设置好友关系列表,格式请参考:http://open.quicksdk.net/help/detail/aid/190 |
| | | |
| | | QuickSdkMgr.I.setGameRoleInfo(roleInfo, false); |
| | | } |
| | | } |
New file |
| | |
| | | package com.secondworld.sdk.command; |
| | | |
| | | import com.quicksdk.entity.GameRoleInfo; |
| | | import com.secondworld.sdk.QuickSdkMgr; |
| | | import com.secondworld.sdk.utils.CodeU2A; |
| | | |
| | | import org.json.JSONObject; |
| | | |
| | | public class CmdRoleLogin implements ICommand { |
| | | @Override |
| | | public int getCode() { |
| | | return CodeU2A.RoleLogin; |
| | | } |
| | | |
| | | @Override |
| | | public void process(JSONObject json) throws Exception { |
| | | GameRoleInfo roleInfo = new GameRoleInfo(); |
| | | roleInfo.setServerID(json.getString("sid")); |
| | | roleInfo.setServerName(json.getString("serverName")); |
| | | roleInfo.setGameRoleName(json.getString("roleName").trim().replace(" ", "")); |
| | | roleInfo.setGameRoleID(json.getString("roleID")); |
| | | roleInfo.setGameBalance(json.getString("money")); |
| | | roleInfo.setVipLevel(json.getString("vipLevel")); //设置当前用户vip等级,必须为数字整型字符串,请勿传"vip1"等类似字符串 |
| | | roleInfo.setGameUserLevel(json.getString("level"));//设置游戏角色等级 |
| | | roleInfo.setPartyName(json.getString("familyName").trim().replace(" ", ""));//设置帮派名称 |
| | | roleInfo.setRoleCreateTime(json.getString("createTime")); //UC,当乐与1881,TT渠道必传,值为10位数时间戳 |
| | | |
| | | roleInfo.setPartyId("1100"); //360渠道参数,设置帮派id,必须为整型字符串 |
| | | roleInfo.setGameRolePower("38"); //360,TT语音渠道参数,设置角色战力,必须为整型字符串 |
| | | roleInfo.setPartyRoleId("11"); //360渠道参数,设置角色在帮派中的id |
| | | roleInfo.setPartyRoleName("帮主"); //360渠道参数,设置角色在帮派中的名称 |
| | | roleInfo.setProfessionId("38"); //360渠道参数,设置角色职业id,必须为整型字符串 |
| | | roleInfo.setProfession("法师"); //360渠道参数,设置角色职业名称 |
| | | roleInfo.setFriendlist("无"); //360渠道参数,设置好友关系列表,格式请参考:http://open.quicksdk.net/help/detail/aid/190 |
| | | |
| | | QuickSdkMgr.I.setGameRoleInfo(roleInfo, false); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <animation-list xmlns:android="http://schemas.android.com/apk/res/android" |
| | | android:oneshot="false" > |
| | | |
| | | <item |
| | | android:drawable="@drawable/qk_game_load01" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load02" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load03" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load04" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load05" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load06" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load07" |
| | | android:duration="50"/> |
| | | <item |
| | | android:drawable="@drawable/qk_game_load08" |
| | | android:duration="50"/> |
| | | |
| | | </animation-list> |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:orientation="vertical" > |
| | | |
| | | <ImageView |
| | | android:id="@+id/qk_img_loading" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:scaleType="center" |
| | | android:src="@drawable/qk_game_loading" /> |
| | | |
| | | </LinearLayout> |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <resources> |
| | | |
| | | <!-- 自定义loading dialog --> |
| | | <style name="qk_game_style_loading" parent="android:style/Theme.Dialog"> |
| | | <item name="android:windowFrame">@null</item> |
| | | <item name="android:windowNoTitle">true</item> |
| | | <item name="android:windowBackground">@drawable/qk_game_loadbg</item> |
| | | <item name="android:windowIsFloating">true</item> |
| | | <item name="android:windowContentOverlay">@null</item> |
| | | </style> |
| | | |
| | | |
| | | |
| | | </resources> |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <paths xmlns:android="http://schemas.android.com/apk/res/android"> |
| | | <external-path |
| | | name="external" |
| | | path="." /> |
| | | </paths> |
New file |
| | |
| | | plugins { |
| | | id 'com.android.library' |
| | | } |
| | | |
| | | android { |
| | | compileSdkVersion 29 |
| | | buildToolsVersion "30.0.2" |
| | | |
| | | defaultConfig { |
| | | minSdkVersion 21 |
| | | targetSdkVersion 29 |
| | | versionCode 1 |
| | | versionName "1.0" |
| | | |
| | | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
| | | consumerProguardFiles "consumer-rules.pro" |
| | | } |
| | | |
| | | buildTypes { |
| | | release { |
| | | minifyEnabled false |
| | | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| | | } |
| | | } |
| | | compileOptions { |
| | | sourceCompatibility JavaVersion.VERSION_1_8 |
| | | targetCompatibility JavaVersion.VERSION_1_8 |
| | | } |
| | | } |
| | | |
| | | dependencies { |
| | | |
| | | implementation 'com.android.support:appcompat-v7:28.0.0' |
| | | testImplementation 'junit:junit:4.+' |
| | | androidTestImplementation 'com.android.support.test:runner:1.0.2' |
| | | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' |
| | | } |