fix: StandardCharsets.UTF_8 替换为 Charset.forName("UTF-8")

Android 4.2(API 17)不支持 java.nio.charset.StandardCharsets(API 19+),
5 个文件统一改用兼容 API 1 的 String 重载:
- DeviceIdentityProvider / HMacShaUtils / Md5Utils: Charset.forName
- UrlParamBuilder: URLEncoder.encode(str, "UTF-8")
- ContentDetailUtils: 删除未使用的 import
This commit is contained in:
zhaogd
2026-08-26 15:51:33 +08:00
parent fca025383c
commit ccc65afcbc
6 changed files with 28 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ import com.pukka.jiecheng.config.AppConfiguration;
import com.pukka.libcore.boxShared.BoxSharedParamsUtils;
import com.pukka.libcore.utils.LogUtils;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.Locale;
@@ -87,7 +87,7 @@ public class DeviceIdentityProvider {
return "";
}
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] hashBytes = digest.digest(source.getBytes(StandardCharsets.UTF_8));
byte[] hashBytes = digest.digest(source.getBytes(Charset.forName("UTF-8")));
int usedBytes = Math.min(MD5_TRUNCATED_BYTES, hashBytes.length);
if (usedBytes <= 0) {
return "";
@@ -112,7 +112,7 @@ public class DeviceIdentityProvider {
return "";
}
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = digest.digest(source.getBytes(StandardCharsets.UTF_8));
byte[] hashBytes = digest.digest(source.getBytes(Charset.forName("UTF-8")));
StringBuilder hexBuilder = new StringBuilder(hashBytes.length * 2);
for (byte hashByte : hashBytes) {
hexBuilder.append(String.format(Locale.ROOT, "%02X", hashByte));

View File

@@ -1,8 +1,8 @@
package com.pukka.jiecheng.utils;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class UrlParamBuilder {
@@ -60,9 +60,15 @@ public class UrlParamBuilder {
urlBuilder.append("&");
}
urlBuilder.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8))
try {
urlBuilder.append(URLEncoder.encode(entry.getKey(), "UTF-8"))
.append("=")
.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8));
.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
urlBuilder.append(entry.getKey())
.append("=")
.append(entry.getValue());
}
}
}

View File

@@ -20,7 +20,6 @@ import com.pukka.jiecheng.R;
import com.pukka.libcore.fresco.PkSimpleDraweeView;
import com.pukka.libcore.utils.LogUtils;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;