Android 获取Web地址栏参数

String url = entity.getTPXW_ImgUrl().toString();

                String[] parameters = { "ClassID" };

                String u;

                try {

                    u = URLDecoder.decode(url, "UTF-8");

                    String[] strLength = new String[0];

                    int strSplit1 = 0;

                    int strSplit2 = 0;

                    String strValue = "";

                    for (String s : parameters) {

                        if (u.indexOf(s) != -1) {

                            strLength = (u.substring(u.indexOf(s))).split("&");

                        }

                        for (int j = 0; j < strLength.length; j++) {

                            strValue += strLength[j];

                        }

                    }

                    if (strLength.length <= 0) {

                        strLength = null;

                    } else {

                        strSplit1 = strValue.indexOf("NewsID=");

                        String value1 = strValue.substring(8, strSplit1);

                        strSplit2 = strValue.lastIndexOf("=");

                        String value2 = strValue.substring(strSplit2 + 1,

                                strValue.length());

                        entity.setTPXW_ClassID(Integer.parseInt(value1));

                        entity.setTPXW_NewsID(Integer.parseInt(value2));

                    }

                } catch (UnsupportedEncodingException e) {

                    e.printStackTrace();

                }

 

你可能感兴趣的:(android)