单板层积材库和Android棉花糖 [英] Lvl library and android marshmallow

查看:112
本文介绍了单板层积材库和Android棉花糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拉​​特库不会再在Android棉花糖由于缺乏apache的东西去掉编译。您可以添加useLibraryorg.apache.http.legacy'',但它只是一个临时的解决方法。问题是这样的方法:

Lvl library doesn't compile anymore on Android Marshmallow due to the lack apache stuff removed. You can add 'useLibrary 'org.apache.http.legacy'' but it's only a temporary workaround. The problem is this method:

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;
    }

的NameValuePair <​​/ code>和 URLEn codedUtils 都没有发现。什么是新的办法?我怎么能代替这个调用新的code符合新的Andr​​oid版本?

NameValuePair and URLEncodedUtils are not found. What is the new "way"? How can I replace this call with new code compliant with the new Android version?

推荐答案

我写我自己的类看着原​​来的code作为暂时的解决办法:

I wrote my own class looking at the original code as temporary workaround:

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棉花糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆