Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Log;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    /**
     * Encode a String of URL into UTF-8, and handles exception by returning a default value.
     * @param url The URL to encode
     */
    public static String urlEncode(String url, String def) {
        try {
            return URLEncoder.encode(url, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Log.w("Transit URL encode", "Unsupported encoding: " + e.getMessage());
            return def;
        }
    }
}