如何从android中的url获取参数? [英] How can i get parameters from url in android?

查看:155
本文介绍了如何从android中的url获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址,如 http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394

请有人帮我查一下章节参数的值并发帖?

Please someone help me to find the value of parameter of chapter and post?

我的网址包含' &'在章节参数的值。

My url contains '&' in the value of chapter parameter.

推荐答案

您可以使用Android中的Uri类来执行此操作; https://developer.android.com/reference/android/net/Uri.html

You can use the Uri class in Android to do this; https://developer.android.com/reference/android/net/Uri.html

Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
String server = uri.getAuthority();
String path = uri.getPath();
String protocol = uri.getScheme();
Set<String> args = uri.getQueryParameterNames();

然后您甚至可以从查询参数中获取特定元素;

Then you can even get a specific element from the query parameters as such;

String chapter = uri.getQueryParameter("chapter");  //will return "V-Maths-Addition "

这篇关于如何从android中的url获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆