Hello. So I am doing a simple webview implementati...
# compose-android
s
Hello. So I am doing a simple webview implementation for a payment system and I am trying to manually handle the redirects. I am checking the url when it changes, so that I can act accordingly. However when I try to access the
url?.host
, when I debug it. I see "NOT CACHED" as the message. I absolutely don't know what this means and no information from the internet seems to help. I will drop an SS of my implementation and my webview settings below
Screenshot 2025-03-28 at 7.31.07 PM.png
Copy code
settings.apply {
                        javaScriptEnabled = true
                        javaScriptCanOpenWindowsAutomatically = true
                        domStorageEnabled = true
                        cacheMode = WebSettings.LOAD_NO_CACHE
                    }
my webview settings
The host returns "NOT CACHED" string thereby making my if check to not get through
Does this have to do with webview implementation or how the url is handled by the server?
I mean like, front end interface
c
https is a scheme so the current code will not work. host would be example.com only. Refer to this image for more.
s
I see, so I should make use of http instead of https?
c
Nope, I mean url?.host will return only “example.com” in your case which won’t match with “https://example.com” which you are trying to match. In the pic that I sent above, you can see what is the format of host and other different component of uri as well. Refer to this image and make conditional check based on that.
s
Yeah, I will do that
But the issue is that url.host doesn't even return that. I placed a debugger at the if check, just before it runs and when I check the url?.host, I see NOT CAHCHED, even the scheme says the same thing
So even if I do the correct conditional check, the code might still not work
Should I show a picture of my debugger to explain better?
c
NOT CACHED means probably the line hasn’t run yet. Put the breakpoint on next line and hover to the url?.host. That might work.
1
s
Okay let me try that
Thank you very much. It does work. I guess all this time, I was getting it wrong. But then again I guess the paystack documentation was kind of misleading in that aspect, because that is what I was following actually
c
Might be, afaik, if it’s a variable and has already been evaluated once, the result would be cached and would be shown when hovered. Can you paste the link to documentation that you are following?
s
c
yeah, looks like the docs need correction. maybe it is safe to use
contains()
. For eg:
url?.toString()?.contains(callbackUrl)
or
startsWith()
should work as well.
s
I see. Thanks. But the url?.host isn't bad too right?
c
Yeah, we can only compare host as well here.
👍 1