添加uc接入代码

This commit is contained in:
zhl 2020-11-27 16:19:07 +08:00
parent b2e58d4462
commit f8c016c722
28 changed files with 255 additions and 87 deletions

View File

@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.hnjc.wjtx.mi"
applicationId "com.hnjc.wjtx.aligames"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
@ -39,4 +39,6 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.jakewharton:butterknife:8.2.1'
annotationProcessor('com.jakewharton:butterknife-compiler:8.2.1')
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -83,7 +83,7 @@
-dontwarn android.support.**
-keep class **.R$styleable{*;}
-keep class com.hnjc.wjtx.mi.** { *; }
-keep class com.hnjc.wjtx.aligames.** { *; }
-dontwarn com.hnjc.wjtx.mi.**

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hnjc.wjtx">
xmlns:tools="http://schemas.android.com/tools"
package="com.hnjc.wjtx.aligames">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@ -10,8 +12,16 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<application
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/ic_launcher"
android:name=".JCApplication"
android:label="@string/app_name"
@ -38,19 +48,45 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
<!-- 增加app拉起相关cn.uc.gamesdk.activity.PullupActivity的声明 -->
<activity
android:name="cn.uc.gamesdk.activity.PullupActivity"
android:theme="@android:style/Theme.Translucent"
android:taskAffinity="com.hnjc.wjtx.aligames.diff"
android:excludeFromRecents="true"
android:label="PullupActivity"
android:launchMode="singleTop"
android:exported="true"
tools:node="replace">
<!-- <activity android:name=".MainActivity"-->
<!-- android:launchMode="singleTask"-->
<!-- android:screenOrientation="portrait"-->
<!-- android:windowSoftInputMode="adjustPan|stateAlwaysVisible"-->
<!-- android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"-->
<!-- android:theme="@android:style/Theme.NoTitleBar.Fullscreen">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<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="ng119474" />
</intent-filter>
</activity>
<activity
android:name="cn.gundam.sdk.shell.activity.ProxyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="cn.uc.gamesdk.sdkweb" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- sdk service -->
<service
android:name="cn.gundam.sdk.shell.service.ProxyService"
android:exported="true"
android:process=":bgservice" />
<!-- sdk service end -->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
</application>

View File

@ -1,12 +0,0 @@
package com.hnjc.wjtx;
import android.app.Application;
import android.util.Log;
public class JCApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Log.i("JCApplication", "JCApplication onCreate");
}
}

View File

@ -0,0 +1,18 @@
package com.hnjc.wjtx.aligames;
import android.app.Application;
import android.util.Log;
import cn.uc.gamesdk.SDKHelper;
public class JCApplication extends Application {
@Override
public void onCreate() {
Log.i("JCApplication", "JCApplication onCreate");
if(!SDKHelper.isBackground(this)){
//调用super方法
super.onCreate();
//表示当前为SDK所属的子进程不应该再执行其他游戏相关的初始化
}
}
}

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx;
package com.hnjc.wjtx.aligames;
import android.Manifest;
import android.app.Activity;
@ -12,12 +12,12 @@ import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.hnjc.wjtx.net.DownloadRunnable;
import com.hnjc.wjtx.net.TaskInfo;
import com.hnjc.wjtx.net.WebApi;
import com.hnjc.wjtx.util.AssetsUtil;
import com.hnjc.wjtx.util.StringUtil;
import com.hnjc.wjtx.util.UnzipRunnable;
import com.hnjc.wjtx.aligames.net.DownloadRunnable;
import com.hnjc.wjtx.aligames.net.TaskInfo;
import com.hnjc.wjtx.aligames.net.WebApi;
import com.hnjc.wjtx.aligames.util.AssetsUtil;
import com.hnjc.wjtx.aligames.util.StringUtil;
import com.hnjc.wjtx.aligames.util.UnzipRunnable;
import org.json.JSONException;
import org.json.JSONObject;

View File

@ -1,8 +1,8 @@
package com.hnjc.wjtx;
package com.hnjc.wjtx.aligames;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
@ -16,15 +16,25 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import com.hnjc.wjtx.util.AssetsUtil;
import com.hnjc.wjtx.util.IdUtil;
import com.hnjc.wjtx.util.StorageUtil;
import com.hnjc.wjtx.util.StringUtil;
import com.hnjc.wjtx.aligames.util.AssetsUtil;
import com.hnjc.wjtx.aligames.util.StorageUtil;
import com.hnjc.wjtx.aligames.util.StringUtil;
import org.egret.egretnativeandroid.EgretNativeAndroid;
import org.json.JSONException;
import org.json.JSONObject;
import cn.gundam.sdk.shell.even.SDKEventKey;
import cn.gundam.sdk.shell.even.SDKEventReceiver;
import cn.gundam.sdk.shell.even.Subscribe;
import cn.gundam.sdk.shell.exception.AliLackActivityException;
import cn.gundam.sdk.shell.exception.AliNotInitException;
import cn.gundam.sdk.shell.open.ParamInfo;
import cn.gundam.sdk.shell.open.UCOrientation;
import cn.gundam.sdk.shell.param.SDKParamKey;
import cn.gundam.sdk.shell.param.SDKParams;
import cn.uc.gamesdk.UCGameSdk;
//Android项目发布设置详见doc目录下的README_ANDROID.md
public class MainActivity extends Activity {
@ -40,7 +50,7 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState);
String preloadPath = AssetsUtil.getDiskFileDir(this, this.getString(R.string.preload_path));
String gameUrl = this.getString(R.string.game_url);
nativeAndroid = new EgretNativeAndroid(this);
if (!nativeAndroid.checkGlEsVersion()) {
@ -59,7 +69,7 @@ public class MainActivity extends Activity {
nativeAndroid.config.preloadPath = preloadPath;
setExternalInterfaces();
String gameUrl = this.getString(R.string.game_url);
if (!nativeAndroid.initialize(gameUrl)) {
Toast.makeText(this, "Initialize native failed.",
Toast.LENGTH_LONG).show();
@ -67,10 +77,19 @@ public class MainActivity extends Activity {
}
setContentView(nativeAndroid.getRootFrameLayout());
rootLayout = nativeAndroid.getRootFrameLayout();
nativeAndroid.pause();
showLoadingView();
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
ucNetworkAndInitUCGameSDK();
UCGameSdk.defaultSdk().registerSDKEventReceiver(receiver);
}
public void startGame() {
nativeAndroid.resume();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ucNetworkAndInitUCGameSDK();
}
@Override
protected void onPause() {
super.onPause();
@ -86,19 +105,11 @@ public class MainActivity extends Activity {
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//声明并初始化弹出对象
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("提示:");
builder.setMessage("是否退出");
//设置确认按钮
builder.setNegativeButton("确定", (dialog, which) -> {
nativeAndroid.exitGame();
finish();//退出程序
});
//设置取消按钮
builder.setPositiveButton("取消",null);
//显示弹框
builder.show();
try {
UCGameSdk.defaultSdk().exit(this, null);
} catch (Exception e) {
e.printStackTrace();
}
return true;
} else {
return super.onKeyDown(keyCode, keyEvent);
@ -163,18 +174,7 @@ public class MainActivity extends Activity {
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
});
nativeAndroid.setExternalInterface("getUid", message -> {
//TODO: 平台的登陆
JSONObject obj = new JSONObject();
try {
obj.put("openid", IdUtil.getUid(this));
obj.put("token", "");
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
obj.put("errorcode", 1);
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
nativeAndroid.callExternalInterface("loginCancel", "");
}
ucSdkLogin();
});
nativeAndroid.setExternalInterface("@onState", message -> {
@ -266,4 +266,111 @@ public class MainActivity extends Activity {
launchScreenImageView = null;
}
public void ucNetworkAndInitUCGameSDK() {
//!!!在调用SDK初始化前进行网络检查
//当前没有拥有网络
ucSdkInit();//执行UCGameSDK初始化
}
private void ucSdkInit() {
ParamInfo gameParamInfo = new ParamInfo();
gameParamInfo.setGameId(UCSdkConfig.gameId);
gameParamInfo.setOrientation(UCOrientation.PORTRAIT);
SDKParams sdkParams = new SDKParams();
sdkParams.put(SDKParamKey.GAME_PARAMS, gameParamInfo);
try {
UCGameSdk.defaultSdk().initSdk(this, sdkParams);
} catch (AliLackActivityException e) {
e.printStackTrace();
}
}
private void ucSdkLogin() {
try {
UCGameSdk.defaultSdk().login(this, null);
} catch (AliLackActivityException e) {
e.printStackTrace();
} catch (AliNotInitException e) {
e.printStackTrace();
}
}
private void ucSdkPay() {
// Intent intent = new Intent(MainActivity.this, GamePayActivity.class);
// MainActivity.this.startActivity(intent);
}
SDKEventReceiver receiver = new SDKEventReceiver() {
@Subscribe(event = SDKEventKey.ON_INIT_SUCC)
private void onInitSucc() {
startGame();
}
@Subscribe(event = SDKEventKey.ON_INIT_FAILED)
private void onInitFailed(String data) {
//初始化失败
Toast.makeText(MainActivity.this, "init failed", Toast.LENGTH_SHORT).show();
Log.i(TAG, "UC SDK init failed");
ucNetworkAndInitUCGameSDK();
}
@Subscribe(event = SDKEventKey.ON_LOGIN_SUCC)
private void onLoginSucc(String sid) {
JSONObject obj = new JSONObject();
try {
obj.put("openid", sid);
obj.put("token", "");
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
nativeAndroid.callExternalInterface("loginCancel", "");
}
}
@Subscribe(event = SDKEventKey.ON_LOGIN_FAILED)
private void onLoginFailed(String desc) {
nativeAndroid.callExternalInterface("loginCancel", desc);
}
@Subscribe(event = SDKEventKey.ON_LOGOUT_SUCC)
private void onLogoutSucc() {
nativeAndroid.callExternalInterface("loginOut", "");
// AccountInfo.instance().setSid("");
ucSdkLogin();
}
@Subscribe(event = SDKEventKey.ON_LOGOUT_FAILED)
private void onLogoutFailed() {
Toast.makeText(MainActivity.this, "logout failed", Toast.LENGTH_SHORT).show();
// printMsg("注销失败");
}
@Subscribe(event = SDKEventKey.ON_EXIT_SUCC)
private void onExit(String desc) {
nativeAndroid.exitGame();
finish();//退出程序
// // 退出程序
// Intent intent = new Intent(Intent.ACTION_MAIN);
// intent.addCategory(Intent.CATEGORY_HOME);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// android.os.Process.killProcess(android.os.Process.myPid());
// printMsg(desc);
}
@Subscribe(event = SDKEventKey.ON_EXIT_CANCELED)
private void onExitCanceled(String desc) {
Toast.makeText(MainActivity.this, desc, Toast.LENGTH_SHORT).show();
}
};
}

View File

@ -0,0 +1,14 @@
package com.hnjc.wjtx.aligames;
public class UCSdkConfig {
// 以下参数仅供测试在正式集成SDK时需要使用正式的id数据
// 游戏开发人员需要跟自己的商务或运营人员联系获取
public static final int gameId = 1179479;
public static final String sign_key = "bf4dcf740ca7cd6f0980e4d8fa7f77b0";
}

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import android.content.Context;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import org.json.JSONObject;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
public class BaseMode {
private boolean status;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import android.util.Log;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
public class RequestErrorEvent {
private int type;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import org.json.JSONObject;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
public class TaskInfo {
private String name;//文件名

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import android.content.Context;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.net;
package com.hnjc.wjtx.aligames.net;
import android.content.Context;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.util;
package com.hnjc.wjtx.aligames.util;
import android.content.Context;
import android.content.res.AssetManager;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.util;
package com.hnjc.wjtx.aligames.util;
import android.content.ContentResolver;
import android.content.Context;
@ -20,7 +20,7 @@ public class IdUtil {
while (enumeration.hasMoreElements()) {
NetworkInterface netInterface = enumeration.nextElement();
if (netInterface.getName().equals("wlan0")) {
return com.hnjc.wjtx.util.StringUtil.getMD5(netInterface.getHardwareAddress().toString(), false);
return com.hnjc.wjtx.aligames.util.StringUtil.getMD5(netInterface.getHardwareAddress().toString(), false);
}
}
} catch (Exception e) {
@ -59,9 +59,9 @@ public class IdUtil {
ContentResolver resolver = context.getContentResolver();
String wifiMac = getWifiMac();
String androidId = getAndroidId(resolver);
if (com.hnjc.wjtx.util.StringUtil.notBlank(androidId)) {
if (com.hnjc.wjtx.aligames.util.StringUtil.notBlank(androidId)) {
return androidId;
} else if (com.hnjc.wjtx.util.StringUtil.notBlank(wifiMac)) {
} else if (com.hnjc.wjtx.aligames.util.StringUtil.notBlank(wifiMac)) {
return wifiMac;
} else {
return getUniquePsuedoID();

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.util;
package com.hnjc.wjtx.aligames.util;
import android.content.SharedPreferences;

View File

@ -1,4 +1,4 @@
package com.hnjc.wjtx.util;
package com.hnjc.wjtx.aligames.util;
import java.security.MessageDigest;

View File

@ -1,8 +1,8 @@
package com.hnjc.wjtx.util;
package com.hnjc.wjtx.aligames.util;
import android.util.Log;
import com.hnjc.wjtx.net.TaskInfo;
import com.hnjc.wjtx.aligames.net.TaskInfo;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

View File

@ -3,7 +3,7 @@
<string name="load_game">下载游戏资源</string>
<string name="start_game">进入游戏</string>
<string name="preload_path">preload</string>
<string name="game_url">http://local/index.html?channel=7103</string>
<string name="game_url">http://local/index.html?channel=7110</string>
<string name="local_version">1.0.0</string>
<string name="load_back">load_back</string>
<string name="launch_version">获取游戏版本</string>

View File

@ -15,6 +15,9 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.3"
}
}