Decode url in UTF-8 - Android java.net

Android examples for java.net:URL

Description

Decode url in UTF-8

Demo Code

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Environment;
import android.text.format.DateFormat;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;

public class Main{

    public static String urlDecode(String src) {
        try {/*from   w ww  .j a v  a 2 s . co m*/
            if (src.indexOf("%20") > -1) {
                src = src.replace("%20", "+");
            }

            String str = URLDecoder.decode(src, "UTF-8");

            return str;
        } catch (Exception e) {
            LogUtil.e(e.getMessage());
            return "";
        }
    }

}

Related Tutorials