get HTTP Response Charset - Android Network

Android examples for Network:HTTP Response

Description

get HTTP Response Charset

Demo Code


//package com.java2s;

import android.text.TextUtils;

public class Main {
    public static final String DEFAULT_CHARSET = "UTF-8";

    private static String getResponseCharset(String ctype) {
        String charset = DEFAULT_CHARSET;

        if (!TextUtils.isEmpty(ctype)) {
            String[] params = ctype.split(";");
            for (String param : params) {
                param = param.trim();/*from w  w w .j a va 2s  .c  om*/
                if (param.startsWith("charset")) {
                    String[] pair = param.split("=", 2);
                    if (pair.length == 2) {
                        if (!TextUtils.isEmpty(pair[1])) {
                            charset = pair[1].trim();
                        }
                    }
                    break;
                }
            }
        }

        return charset;
    }
}

Related Tutorials