Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Bundle;

import java.net.URL;
import java.net.URLDecoder;

public class Main {
    public static Bundle urlToBundle(String url) {
        int index = url.indexOf("://");
        if (index >= 0) {
            url = "http://" + url.substring(index + 1);
        } else {
            url = "http://" + url;
        }

        try {
            URL e = new URL(url);
            Bundle b = decodeUrl(e.getQuery());
            b.putAll(decodeUrl(e.getRef()));
            return b;
        } catch (Throwable var4) {
            return new Bundle();
        }
    }

    public static Bundle decodeUrl(String s) {
        Bundle params = new Bundle();
        if (s != null) {
            String[] array = s.split("&");
            String[] arr$ = array;
            int len$ = array.length;

            for (int i$ = 0; i$ < len$; ++i$) {
                String parameter = arr$[i$];
                String[] v = parameter.split("=");
                if (v.length >= 2 && v[1] != null) {
                    params.putString(URLDecoder.decode(v[0]), URLDecoder.decode(v[1]));
                } else {
                    params.putString(URLDecoder.decode(v[0]), "");
                }
            }
        }

        return params;
    }
}