更新vivo的sdk至4.6.9.0

This commit is contained in:
zhl 2021-10-21 10:09:06 +08:00
parent e44feebebd
commit f580b092ea
16 changed files with 218 additions and 181 deletions

View File

@ -1,42 +1,33 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileSdkVersion 26
defaultConfig {
applicationId "com.hnjc.wjtx.vivo"
minSdkVersion 21
targetSdkVersion 28
versionCode 6
versionName "1.0.6"
targetSdkVersion 26
versionCode 9
versionName "1.0.9"
ndk {
abiFilters 'armeabi-v7a'
}
}
buildTypes {
release {
minifyEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['../assets']
aidl.srcDirs = ['aidl']
jniLibs.srcDirs = ['libs']//so&jar文件路径
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildToolsVersion '28.0.3'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'org.greenrobot:eventbus:3.2.0'
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.hnjc.wjtx">
<!--联运SDK跳转游戏中心-->
<uses-permission android:name="vivo.game.permission.OPEN_JUMP_INTENTS"/>
<!--联运SDK监听网络状态变化在支付登录过程中做一些异常处理-->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<!--允许程序访问Wi-Fi网络状态信息-->
@ -23,7 +25,6 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="vivo.game.permission.OPEN_JUMP_INTENTS" />
<application
android:allowBackup="false"
@ -55,12 +56,17 @@
</activity>
<meta-data
android:name="vivo_union_sdk"
android:value="4.6.9.0" />
<!-- vivo sdk componets start -->
<!--vivo sdk的Activity-->
<activity android:name="com.vivo.unionsdk.ui.UnionActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
android:theme="@android:style/Theme.Dialog"
android:exported="false">
android:exported="false"
tools:ignore="AppLinkUrlError">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
@ -72,9 +78,6 @@
</intent-filter>
</activity>
<!-- vivo sdk componets end -->
<meta-data
android:name="vivo_union_sdk"
android:value="4.6.9.0" />
</application>
</manifest>

View File

@ -6,7 +6,6 @@ import android.util.Log;
import com.hnjc.wjtx.vivo.VivoUnionHelper;
import com.vivo.unionsdk.open.MissOrderEventHandler;
import com.vivo.unionsdk.open.OrderResultInfo;
import com.vivo.unionsdk.open.VivoUnionSDK;
import java.util.ArrayList;
import java.util.List;
@ -17,8 +16,7 @@ public class JCApplication extends Application {
public void onCreate() {
super.onCreate();
Log.i("JCApplication", "JCApplication onCreate");
String appId = this.getString(R.string.app_id);
VivoUnionSDK.initSdk(this, appId, false);
VivoUnionHelper.initSdk(this, false);
/**
* 掉单注册接口 需要接入掉单补单处理的一定要加
@ -32,19 +30,22 @@ public class JCApplication extends Application {
/**
* 用户主动触发或调用queryMissOrderResult查询回调会在此做处理
*/
private final MissOrderEventHandler mMissOrderEventHandler = orderResultInfos -> {
Log.i(TAG, "registerOrderResultEventHandler: orderResultInfos = " + orderResultInfos);
/**
* 注意这里是查到未核销的订单
* 需要调用自己的逻辑完成道具核销后再调用我们的订单完成接口
* 切记一定要走自己逻辑发送完道具后再调用完成接口切记切记
* 游戏根据订单号检查补发商品
* 自行完成补发逻辑 一定要完成道具补发后才能调用完成接口 此处一定要注意
* 如果不处理直接调用完成则掉单无法解决
* 注意注意
* 游戏侧用你们自己的订单号cpOrderNumber来校验是否完成发货 发货完成上报我们的订单号transNo
*/
checkOrder(orderResultInfos);
private MissOrderEventHandler mMissOrderEventHandler = new MissOrderEventHandler() {
@Override
public void process(List orderResultInfos) {
Log.i(TAG, "registerOrderResultEventHandler: orderResultInfos = " + orderResultInfos);
/**
* 注意这里是查到未核销的订单
* 需要调用自己的逻辑完成道具核销后再调用我们的订单完成接口
* 切记一定要走自己逻辑发送完道具后再调用完成接口切记切记
* 游戏根据订单号检查补发商品
* 自行完成补发逻辑 一定要完成道具补发后才能调用完成接口 此处一定要注意
* 如果不处理直接调用完成则掉单无法解决
* 注意注意
* 游戏侧用你们自己的订单号cpOrderNumber来校验是否完成发货 发货完成上报我们的订单号transNo
*/
checkOrder(orderResultInfos);
}
};
/**
* 校验订单是否已经完成发货游戏自己逻辑

View File

@ -12,6 +12,7 @@ import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.hnjc.wjtx.net.BaseInterface;
import com.hnjc.wjtx.net.DownloadRunnable;
import com.hnjc.wjtx.net.TaskInfo;
import com.hnjc.wjtx.net.WebApi;
@ -163,44 +164,47 @@ public class LaunchActivity extends Activity {
* 获取远程资源的版本号
*/
private void getRemoteVersionInfo() {
webApi.getVersionInfo((success, message, err) -> {
if (success) {
try {
remoteVersion = message.getString("version");
zipUrl = message.getString("path");
Log.i(TAG, "base version: " + baseVersion);
Log.i(TAG, "local version: " + localVersion);
Log.i(TAG, "remote version: " + remoteVersion);
Log.i(TAG, "remote resource: " + zipUrl);
boolean needUpdate = false;
if (StringUtil.compareAppVersion(baseVersion, localVersion) >= 0) {
if (StringUtil.compareAppVersion(remoteVersion, baseVersion) > 0) {
needUpdate = true;
}
} else {
if (StringUtil.compareAppVersion(remoteVersion, localVersion) > 0) {
needUpdate = true;
}
}
if (needUpdate) {
if (StringUtil.isBlank(zipUrl)) {
Log.e(TAG, "远程版本高于代码包版本和预加载版本, 需要更新, 但未获取到远程资源地址");
startMain();
webApi.getVersionInfo(new BaseInterface() {
@Override
public void response(boolean success, JSONObject message, String err) {
if (success) {
try {
remoteVersion = message.getString("version");
zipUrl = message.getString("path");
Log.i(TAG, "base version: " + baseVersion);
Log.i(TAG, "local version: " + localVersion);
Log.i(TAG, "remote version: " + remoteVersion);
Log.i(TAG, "remote resource: " + zipUrl);
boolean needUpdate = false;
if (StringUtil.compareAppVersion(baseVersion, localVersion) >= 0) {
if (StringUtil.compareAppVersion(remoteVersion, baseVersion) > 0) {
needUpdate = true;
}
} else {
Log.i(TAG, "远程版本高于代码包版本和预加载版本, 需要更新");
updateProgress(100);
preloadGame();
if (StringUtil.compareAppVersion(remoteVersion, localVersion) > 0) {
needUpdate = true;
}
}
} else {
if (needUpdate) {
if (StringUtil.isBlank(zipUrl)) {
Log.e(TAG, "远程版本高于代码包版本和预加载版本, 需要更新, 但未获取到远程资源地址");
startMain();
} else {
Log.i(TAG, "远程版本高于代码包版本和预加载版本, 需要更新");
updateProgress(100);
preloadGame();
}
} else {
startMain();
}
} catch (JSONException e) {
e.printStackTrace();
startMain();
}
} catch (JSONException e) {
e.printStackTrace();
} else {
startMain();
}
} else {
startMain();
}
});
}

View File

@ -32,6 +32,7 @@ import com.vivo.unionsdk.open.VivoRoleInfo;
import com.vivo.unionsdk.open.VivoUnionSDK;
import org.egret.egretnativeandroid.EgretNativeAndroid;
import org.egret.runtime.launcherInterface.INativePlayer;
import org.json.JSONException;
import org.json.JSONObject;
@ -132,7 +133,7 @@ public class MainActivity extends Activity {
nativeAndroid.config.preloadPath = preloadPath;
setExternalInterfaces();
if (!nativeAndroid.initialize(gameUrl)) {
Toast.makeText(this, "Initialize native failed.",
Toast.LENGTH_LONG).show();
@ -206,105 +207,148 @@ public class MainActivity extends Activity {
}
private void setExternalInterfaces() {
nativeAndroid.setExternalInterface("sendToNative", message -> {
Log.d(TAG, "Get message: " + message);
nativeAndroid.callExternalInterface("sendToJS", "Get message: " + message);
nativeAndroid.setExternalInterface("sendToNative", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "Get message: " + message);
nativeAndroid.callExternalInterface("sendToJS", "Get message: " + message);
}
});
nativeAndroid.setExternalInterface("removeNativeLoading", message -> {
Log.d(TAG, "removeNativeLoading: " + message);
hideLoadingView();
nativeAndroid.setExternalInterface("removeNativeLoading", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "removeNativeLoading: " + message);
hideLoadingView();
}
});
nativeAndroid.setExternalInterface("setLocalStorage", message -> {
Log.d(TAG, "setLocalStorage: " + message);
try{
JSONObject jsonObject = new JSONObject(message);
String key = jsonObject.getString("key");
String val = jsonObject.getString("val");
nativeAndroid.setExternalInterface("setLocalStorage", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "setLocalStorage: " + message);
try{
JSONObject jsonObject = new JSONObject(message);
String key = jsonObject.getString("key");
String val = jsonObject.getString("val");
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
StorageUtil.writeString(sharedPref, key, val);
}
catch (JSONException e) {
Log.e(TAG, " onState message failed to analyze");
}
}
});
nativeAndroid.setExternalInterface("getLocalStorage", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "getLocalStorage: " + message);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
StorageUtil.writeString(sharedPref, key, val);
String val = StorageUtil.readString(sharedPref, message);
nativeAndroid.callExternalInterface("getLocalStorage", val);
}
catch (JSONException e) {
Log.e(TAG, " onState message failed to analyze");
});
nativeAndroid.setExternalInterface("removeLocalStorage", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "removeLocalStorage: " + message);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
StorageUtil.removeString(sharedPref, message);
}
});
});
nativeAndroid.setExternalInterface("getLocalStorage", message -> {
Log.d(TAG, "getLocalStorage: " + message);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
String val = StorageUtil.readString(sharedPref, message);
nativeAndroid.callExternalInterface("getLocalStorage", val);
});
nativeAndroid.setExternalInterface("removeLocalStorage", message -> {
Log.d(TAG, "removeLocalStorage: " + message);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
StorageUtil.removeString(sharedPref, message);
nativeAndroid.setExternalInterface("removeLocalStorage", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "removeLocalStorage: " + message);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
StorageUtil.removeString(sharedPref, message);
}
});
/**
* 震动须添加权限
* <uses-permission android:name="android.permission.VIBRATE"/>
* @param type {int} 震动类型 0: 短震动, 1: 长震动
* */
nativeAndroid.setExternalInterface("vibrate", message -> {
Log.d(TAG, "vibrate: " + message);
message = StringUtil.isBlank(message) ? "0" : message;
int type = Integer.getInteger(message);
long time = type == 0 ? 15 : 500;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(time, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
//deprecated in API 26
vibrator.vibrate(time);
nativeAndroid.setExternalInterface("vibrate", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "vibrate: " + message);
message = StringUtil.isBlank(message) ? "0" : message;
int type = Integer.getInteger(message);
long time = type == 0 ? 15 : 500;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(time, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
//deprecated in API 26
vibrator.vibrate(time);
}
}
});
nativeAndroid.setExternalInterface("showToast", message -> {
Log.d(TAG, "showToast: " + message);
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
});
nativeAndroid.setExternalInterface("getUid", message -> {
loginVivoAccount();
});
nativeAndroid.setExternalInterface("@onState", message -> {
Log.e(TAG, "Get @onState: " + message);
try{
JSONObject jsonObject = new JSONObject(message);
String state = jsonObject.getString("state");
handleStateEvent(state);
nativeAndroid.setExternalInterface("showToast", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.d(TAG, "showToast: " + message);
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
catch (JSONException e) {
Log.e(TAG, " onState message failed to analyze");
});
nativeAndroid.setExternalInterface("getUid", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
loginVivoAccount();
}
});
nativeAndroid.setExternalInterface("@onState", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.e(TAG, "Get @onState: " + message);
try {
JSONObject jsonObject = new JSONObject(message);
String state = jsonObject.getString("state");
handleStateEvent(state);
} catch (JSONException e) {
Log.e(TAG, " onState message failed to analyze");
}
}
});
nativeAndroid.setExternalInterface("@onError", message -> Log.e(TAG, "Get @onError: " + message));
nativeAndroid.setExternalInterface("@onError", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.e(TAG, "Get @onError: " + message);
}
});
// 支付
nativeAndroid.setExternalInterface("pay", message -> {
Log.i(TAG, "receive pay: " + message);
try {
JSONObject jsonObject = new JSONObject(message);
cpPayOrderNumber = jsonObject.getString("cpOrderNumber");
cpOrderAmount = jsonObject.getString("orderAmount");
String notifyUrl = jsonObject.getString("notifyUrl");
String productName = jsonObject.getString("productName");
String productDesc = jsonObject.getString("productDesc");
String sign = jsonObject.getString("vivoSignature");
String extuid = jsonObject.getString("extuid");
//TODO: 平台的支付
VivoPayInfo vivoPayInfo = new VivoPayInfo.Builder()
.setAppId(appId)
.setCpOrderNo(cpPayOrderNumber)
.setNotifyUrl(notifyUrl)
.setOrderAmount(cpOrderAmount)
.setProductName(productName)
.setProductDesc(productDesc)
.setVivoSignature(sign)
.setExtUid(extuid)
.build();
VivoUnionHelper.payV2(this, vivoPayInfo, mVivoPayCallback);
} catch (JSONException e) {
e.printStackTrace();
} catch ( Exception e ) {
e.printStackTrace();
nativeAndroid.setExternalInterface("pay", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.i(TAG, "receive pay: " + message);
try {
JSONObject jsonObject = new JSONObject(message);
cpPayOrderNumber = jsonObject.getString("cpOrderNumber");
cpOrderAmount = jsonObject.getString("orderAmount");
String notifyUrl = jsonObject.getString("notifyUrl");
String productName = jsonObject.getString("productName");
String productDesc = jsonObject.getString("productDesc");
String sign = jsonObject.getString("vivoSignature");
String extuid = jsonObject.getString("extuid");
//TODO: 平台的支付
VivoPayInfo vivoPayInfo = new VivoPayInfo.Builder()
.setAppId(appId)
.setCpOrderNo(cpPayOrderNumber)
.setNotifyUrl(notifyUrl)
.setOrderAmount(cpOrderAmount)
.setProductName(productName)
.setProductDesc(productDesc)
.setVivoSignature(sign)
.setExtUid(extuid)
.build();
VivoUnionHelper.payV2(MainActivity.this, vivoPayInfo, mVivoPayCallback);
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
});
//let data = {
@ -322,19 +366,22 @@ public class MainActivity extends Activity {
// gameRoleGender: giant.Core.hero.gender,
// gameRolePower: giant.Core.hero.power,
// };
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
Log.i(TAG, "Get reportRoleInfo: " + message);
try {
JSONObject jsonObject = new JSONObject(message);
String userRoleId = jsonObject.getString("userRoleId");
String userRoleLevel = jsonObject.getString("userRoleLevel");
String userRoleName = jsonObject.getString("userRoleName");
String serverId = jsonObject.getString("serverId");
String serverName = jsonObject.getString("serverName");
VivoUnionHelper.reportRoleInfo(new VivoRoleInfo(userRoleId, userRoleLevel, userRoleName, serverId, serverName));
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Error reportRoleInfo:" + e);
nativeAndroid.setExternalInterface("reportRoleInfo", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
Log.i(TAG, "Get reportRoleInfo: " + message);
try {
JSONObject jsonObject = new JSONObject(message);
String userRoleId = jsonObject.getString("userRoleId");
String userRoleLevel = jsonObject.getString("userRoleLevel");
String userRoleName = jsonObject.getString("userRoleName");
String serverId = jsonObject.getString("serverId");
String serverName = jsonObject.getString("serverName");
VivoUnionHelper.reportRoleInfo(new VivoRoleInfo(userRoleId, userRoleLevel, userRoleName, serverId, serverName));
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Error reportRoleInfo:" + e);
}
}
});
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import org.greenrobot.eventbus.EventBus;
@ -12,11 +13,14 @@ import java.util.Map;
public class AppRequestUtil {
private static final AppRequestUtil app_request_util = new AppRequestUtil();
private final Response.ErrorListener errorListener = volleyError -> {
RequestErrorEvent event = new RequestErrorEvent();
event.setType(1);
event.setErrorMessage(volleyError.getMessage());
EventBus.getDefault().post(event);
private final Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
RequestErrorEvent event = new RequestErrorEvent();
event.setType(1);
event.setErrorMessage(volleyError.getMessage());
EventBus.getDefault().post(event);
}
};
private AppRequestUtil() {

View File

@ -2,15 +2,11 @@
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@ -19,15 +15,8 @@ buildscript {
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}

View File

@ -16,6 +16,4 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.injected.testOnly=false
android.useAndroidX=true
android.enableJetifier=true
android.injected.testOnly=false

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip