decode a String content with URLDecoder - Android Network

Android examples for Network:URL

Description

decode a String content with URLDecoder

Demo Code


//package com.java2s;

import java.io.IOException;

import java.net.URLDecoder;

import android.text.TextUtils;

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

    public static String decode(String value) {
        return decode(value, DEFAULT_CHARSET);
    }//from  w w w  . j  av a  2  s.  co m

    public static String decode(String value, String charset) {
        String result = null;
        if (!TextUtils.isEmpty(value)) {
            try {
                result = URLDecoder.decode(value, charset);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return result;
    }
}

Related Tutorials