gpt4 book ai didi

android - Lvl 库和 android marshmallow

转载 作者:IT老高 更新时间:2023-10-28 23:10:40 25 4
gpt4 key购买 nike

Lvl 库不再在 Android Marshmallow 上编译,因为删除了缺少 apache 的东西。您可以添加 useLibrary 'org.apache.http.legacy 但这只是一种临时解决方法。问题是这个方法:

private Map<String, String> decodeExtras(String extras) {
Map<String, String> results = new HashMap<String, String>();
try {
URI rawExtras = new URI("?" + extras);
List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
for (NameValuePair item : extraList) {
results.put(item.getName(), item.getValue());
}

} catch (URISyntaxException ignored) {

}
return results;
}

NameValuePairURLEncodedUtils 未找到。

什么是新的“方式”?如何用与新 Android 版本兼容的新代码替换此调用?

最佳答案

我编写了自己的类,将原始代码作为临时解决方法:

public class URLUtils {
private static final String PARAMETER_SEPARATOR = "&";
private static final String NAME_VALUE_SEPARATOR = "=";
private static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";

public static List<Item> parse(final URI uri, final String encoding) {
List<Item> result = Collections.emptyList();
final String query = uri.getRawQuery();
if (query != null && query.length() > 0) {
result = new ArrayList<>();
parse(result, new Scanner(query), encoding);
}
return result;
}

public static void parse(final List<Item> parameters, final Scanner scanner, final String encoding) {
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
if (nameValue.length == 0 || nameValue.length > 2)
throw new IllegalArgumentException("bad parameter");

final String name = decode(nameValue[0], encoding);
String value = null;
if (nameValue.length == 2)
value = decode(nameValue[1], encoding);
parameters.add(new Item(name, value));
}
}


private static String decode (final String content, final String encoding) {
try {
return URLDecoder.decode(content, encoding != null ? encoding : DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException problem) {
throw new IllegalArgumentException(problem);
}
}
}

public class Item {
private String name;
private String value;

public Item(String n, String v) {
name = n;
value = v;
}

public String getName() {
return name;
}

public String getValue() {
return value;
}
}

关于android - Lvl 库和 android marshmallow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32115018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com