version:1.0.1
fix: update:基本跳转对接完成
This commit is contained in:
@@ -402,11 +402,7 @@ public class OpenApkUtils {
|
||||
try {
|
||||
BigDecimal version = new BigDecimal("20240527");
|
||||
BigDecimal bigDecimal = new BigDecimal(versionName);
|
||||
if (bigDecimal.compareTo(version) > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return bigDecimal.compareTo(version) > 0;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "isNewAiApp: " + e.getMessage());
|
||||
return true;
|
||||
@@ -635,77 +631,120 @@ public class OpenApkUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数字符串打开对应页面
|
||||
*
|
||||
* @param paramStr 参数字符串(格式:包名,类名,extra参数,第四项,第五项)
|
||||
*/
|
||||
public void openJxwApp(String paramStr) {
|
||||
if (TextUtils.isEmpty(paramStr)) {
|
||||
Log.e(TAG, "openJxwApp: params is null");
|
||||
Log.e(TAG, "context为空或参数字符串为空");
|
||||
return;
|
||||
}
|
||||
// 分割字符串(使用-1保留空元素,处理连续逗号情况)
|
||||
String[] params = paramStr.split(",", -1);
|
||||
if (params.length < 5) {
|
||||
Log.e(TAG, "参数字符串格式错误,参数数量不足");
|
||||
|
||||
// 1. 按逗号分割整体参数(保留空项,避免丢失字段)
|
||||
String[] totalParts = paramStr.split(",", -1);
|
||||
if (totalParts.length < 2) { // 至少需要包名+类名
|
||||
Log.e(TAG, "参数字符串格式错误:" + paramStr);
|
||||
return;
|
||||
}
|
||||
// 提取各项参数
|
||||
String packageName = params[0];
|
||||
String className = params[1];
|
||||
String extraStr = params[2];
|
||||
String fourthParam = params[3];
|
||||
String fifthParam = params[4];
|
||||
|
||||
try {
|
||||
// 构建Intent
|
||||
Intent intent = new Intent();
|
||||
ComponentName componentName = new ComponentName(packageName, className);
|
||||
intent.setComponent(componentName);
|
||||
// 提取各项基础参数
|
||||
String packageName = totalParts[0]; // 第一项:包名
|
||||
String className = totalParts[1]; // 第二项:类名
|
||||
String extraParamStr = totalParts.length > 2 ? totalParts[2] : ""; // 第三项:Intent Extra参数
|
||||
String fourthParam = totalParts.length > 3 ? totalParts[3] : ""; // 第四项(自定义)
|
||||
String fifthParam = totalParts.length > 4 ? totalParts[4] : ""; // 第五项(自定义)
|
||||
|
||||
// 解析并添加Extra参数
|
||||
if (extraStr != null && !extraStr.isEmpty()) {
|
||||
String[] extraParts = extraStr.split(":", 3);
|
||||
if (extraParts.length == 3) {
|
||||
String type = extraParts[0];
|
||||
String key = extraParts[1];
|
||||
String value = extraParts[2];
|
||||
Log.d(TAG, "包名:" + packageName + "\n类名:" + className
|
||||
+ "\n第四项:" + fourthParam + "\n第五项:" + fifthParam);
|
||||
|
||||
// 根据类型添加Extra
|
||||
switch (type.toLowerCase()) {
|
||||
case "int":
|
||||
intent.putExtra(key, Integer.parseInt(value));
|
||||
break;
|
||||
case "string":
|
||||
intent.putExtra(key, value);
|
||||
break;
|
||||
case "boolean":
|
||||
intent.putExtra(key, Boolean.parseBoolean(value));
|
||||
break;
|
||||
case "long":
|
||||
intent.putExtra(key, Long.parseLong(value));
|
||||
break;
|
||||
// 可扩展支持其他类型(float、double等)
|
||||
default:
|
||||
Log.w(TAG, "不支持的Extra类型:" + type);
|
||||
intent.putExtra(key, value);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Extra参数格式错误:" + extraStr);
|
||||
// 2. 构建Intent并设置Component(包名+类名)
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ComponentName component = new ComponentName(packageName, className);
|
||||
intent.setComponent(component);
|
||||
|
||||
// 3. 解析Extra参数(支持多组,用#分隔;每组格式:类型:key:值)
|
||||
if (!TextUtils.isEmpty(extraParamStr)) {
|
||||
String[] extraGroups = extraParamStr.split("#");
|
||||
for (String extraGroup : extraGroups) {
|
||||
if (TextUtils.isEmpty(extraGroup)) continue;
|
||||
|
||||
// 按冒号分割(最多分3段,避免值中包含冒号)
|
||||
String[] extraParts = extraGroup.split(":", 3);
|
||||
if (extraParts.length != 3) {
|
||||
Log.w(TAG, "Extra参数格式错误:" + extraGroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
String type = extraParts[0]; // 类型(int/String等)
|
||||
String key = extraParts[1]; // Extra的key
|
||||
String value = extraParts[2]; // Extra的value
|
||||
|
||||
// 根据类型设置Extra
|
||||
setExtraByType(intent, type, key, value);
|
||||
}
|
||||
|
||||
// 如需传递第四、五项参数,可根据需求添加
|
||||
// intent.putExtra("fourth_param", fourthParam);
|
||||
// intent.putExtra("fifth_param", fifthParam);
|
||||
|
||||
// 启动Activity(需确保上下文是Activity或添加FLAG_ACTIVITY_NEW_TASK)
|
||||
// if (!(context instanceof android.app.Activity)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// }
|
||||
mContext.startActivity(intent);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "参数类型转换失败", e);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "启动Activity失败", e);
|
||||
}
|
||||
|
||||
// 4. 启动Activity(处理异常)
|
||||
try {
|
||||
mContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof android.content.ActivityNotFoundException) {
|
||||
Log.e(TAG, "未找到目标Activity:" + packageName + "/" + className);
|
||||
} else if (e instanceof SecurityException) {
|
||||
Log.e(TAG, "启动Activity权限不足");
|
||||
} else {
|
||||
Log.e(TAG, "启动Activity失败:" + e.getMessage());
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型为Intent设置Extra参数
|
||||
*
|
||||
* @param intent 目标Intent
|
||||
* @param type 参数类型(int/String/boolean等)
|
||||
* @param key Extra的key
|
||||
* @param value Extra的value字符串
|
||||
*/
|
||||
private static void setExtraByType(Intent intent, String type, String key, String value) {
|
||||
if (TextUtils.isEmpty(type) || TextUtils.isEmpty(key)) return;
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case "int":
|
||||
try {
|
||||
int intValue = Integer.parseInt(value);
|
||||
intent.putExtra(key, intValue);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.w(TAG, "int类型转换失败:" + value);
|
||||
}
|
||||
break;
|
||||
case "string":
|
||||
intent.putExtra(key, value);
|
||||
break;
|
||||
case "boolean":
|
||||
try {
|
||||
boolean boolValue = Boolean.parseBoolean(value);
|
||||
intent.putExtra(key, boolValue);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "boolean类型转换失败:" + value);
|
||||
}
|
||||
break;
|
||||
case "long":
|
||||
try {
|
||||
long longValue = Long.parseLong(value);
|
||||
intent.putExtra(key, longValue);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.w(TAG, "long类型转换失败:" + value);
|
||||
}
|
||||
break;
|
||||
// 可扩展其他类型(float/double等)
|
||||
default:
|
||||
Log.w(TAG, "不支持的参数类型:" + type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user