decode Url to Bundle - Android Android OS

Android examples for Android OS:Bundle Get

Description

decode Url to Bundle

Demo Code


//package com.java2s;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import android.os.Bundle;

public class Main {

    public static Bundle decodeUrl(String s) {
        Bundle params = new Bundle();
        if (s != null) {
            String array[] = s.split("&");
            for (String parameter : array) {
                String[] paramArr = parameter.split("=");
                if (paramArr != null && paramArr.length == 2) {
                    try {
                        params.putString(
                                URLDecoder.decode(paramArr[0], "UTF-8"),
                                URLDecoder.decode(paramArr[1], "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }//w w w.  ja  v a2s .  c  o  m
                }
            }
        }
        return params;
    }
}

Related Tutorials