encode Html with URLEncoder for WebView - Android User Interface

Android examples for User Interface:WebView URL

Description

encode Html with URLEncoder for WebView

Demo Code


import android.util.Log;
import java.net.URLEncoder;

public class Main{
    public static final String UTF8 = "utf-8";
    public static String encodeHtml(String content) {
        try {//from w  w  w.jav a  2 s .c  o m
            return URLEncoder.encode(content, UTF8).replaceAll("\\+", " ");
        } catch (Exception e) {
            Log.e(WebUtils.class.getName(),
                    "Error encoding html in UTF8 : " + e.getMessage());
            return content;
        }
    }
}

Related Tutorials