I have next uri:
How i can parse my code?
d5215173-2be3-4491-bf2a-d9d039a50e97
I tried to do smth like this:
val uri: Uri = Uri.parse(url)
val code: String = uri.getQueryParameter("code").toString()
But it doesn't work for me.
CodePudding user response:
Right now i solved this problem with next solution:
val url: String = Uri.parse(url).toString()
var code = ""
if (url.contains("#code=")) {
code = url.substring(url.indexOf("#code=") 6)
if (code.contains("&")) {
code = code.split("&")[0]
}
}
CodePudding user response:
Also you could do it with a Regex:
val url = Uri.parse(url).toString()
var code = ""
val matcher = Pattern.compile("#code=. &").matcher(url)
if (matcher.find())
code = url.slice(matcher.start() 6 until matcher.end() - 1)