1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android获取webView加载H5链接 截取url参数

android获取webView加载H5链接 截取url参数

时间:2023-01-14 21:56:08

相关推荐

android获取webView加载H5链接 截取url参数

public class HttpUtil {

/***

* 获取url 指定name的value;

* @param url

* @param name 工具类

* @return

*/

public static String getValueByName(String url, String name) {

String result = “”;

int index = url.indexOf(“?”);

String parameters = url.substring(index + 1);

String[] keyValue = parameters.split(“&”);

for (String str : keyValue) {

if (str.contains(name)) {

result = str.replace(name + “=”, “”);

break;

}

}

return result;

}

}

activity中调用 ,json格式给到接口就行了 (当然看后端接口要求)->

JSONObject jsonObject = new JSONObject();

jsonObject.put(“videoId”, HttpUtil.getValueByName(webUrl, “videoId”));

jsonObject.put(“currentIndex”, HttpUtil.getValueByName(webUrl, “currentIndex”));

sonObject.toJSONString()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。