Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.URLDecoder;

import android.os.Bundle;
import android.text.TextUtils;

public class Main {
    /**
     * Decode parameters contained in the provided String and generate a {@link Bundle} associating
     * parameters name and values.
     * 
     * @param url
     *            Url that we decode parameters from.
     * @return Bundle containing decoded parameters.
     */
    public static Bundle decodeUrl(String url) {
        Bundle bundle = new Bundle();
        if (!TextUtils.isEmpty(url) && url.indexOf("?") != -1) {
            String urlParameters = url.substring(url.indexOf("?") + 1);
            String[] parameters = urlParameters.split("&");
            for (String parameter : parameters) {
                String[] keyValue = parameter.split("=");
                if (keyValue.length == 2) {
                    bundle.putString(URLDecoder.decode(keyValue[0]), URLDecoder.decode(keyValue[1]));
                }
            }
        }

        return bundle;
    }
}