Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.os.Bundle;

import java.net.URLDecoder;

public class Main {
    /**
     * @param url
     * @return bundle that contains key-value entries of the url query and fragment.
     */
    public static final Bundle getUrlParameters(final String url) {
        final Bundle bundle = new Bundle();
        final String[] separated = url.split("\\?");
        if (separated.length > 1) {
            final String query = separated[1];
            final String[] params = query.split("[&#]");
            for (final String param : params) {
                final String[] keyvalue = param.split("=");
                final String key = URLDecoder.decode(keyvalue[0]);
                String value = null;
                if (keyvalue.length > 1) {
                    value = URLDecoder.decode(keyvalue[1]);
                }
                bundle.putString(key, value);
            }
        }
        return bundle;
    }
}