Android Question Webview and redirects

adriano.freitas

Active Member
I have been using webview and it has worked perfectly for what I need, however, now I need it to open links from two platforms and they do not work (I need to open these links without using an external browser). I think it's because they use redirects.

URL examples:



and


https://music.amazon.com.br/podcast...e45-56c65340ed28/episodes/f138808d-a044-44a4- 94e7-a2c7e75ca245/neuroci%C3%AAncias-por-adriano-freitas-uff-0265---o-c%C3%A9rebro-e-suas-ilus%C3%B5es


Does anyone know of a solution to open these links without using an external browser?


Thanks!
 

adriano.freitas

Active Member
What happens when you try to open them?

You can get more information about errors with: https://www.b4x.com/android/forum/threads/problem-with-webview-javascript.165062/#post-1012042
Links like these use redirects. When they are accessed, the URL changes, being handled either by an app of platform if it is installed or by the platform's website. It seems to me that he's not dealing with it well and when he switches to an intent or something similar, he doesn't do anything.

The result is an empty webview, with nothing in it.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the site can recognize an android webview (you might want to try changing the user-agent). when this occurs, it redirects the user to a url whose scheme is "intent://". this is meant to launch the appropriate app on the user's device. you can possibly work around this by intercepting webview client's shouldOverrideUrlLoading method.
obviously you could change the scheme to https://, but that doesn't necessarily mean you're going to get a webpage as a result. by using "intent" deep-linking, the site wants to launch an app, not serve a webpage. by changing the user agent, you might get a few steps further, but the site is expecting you to have that app. if you use shouldOverrideUrlLoading, you would return true (to abort the loading) and then launch the app. when the site detects a desktop browser, it just does a normal redirect.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here. this will play your music. accept the cookies and you're good to go. don't complain about how it looks; it's not meant to run in a webview. either you want to hear the music or you don't. or you get the app that the site wants in order to run on mobile.
 

Attachments

  • freitas.zip
    8.6 KB · Views: 49
Upvote 0

adriano.freitas

Active Member
here. this will play your music. accept the cookies and you're good to go. don't complain about how it looks; it's not meant to run in a webview. either you want to hear the music or you don't. or you get the app that the site wants in order to run on mobile.
I really appreciate your availability and attention. I will look at the file, however, my question is not specific to audio, music. I cited these sites as an example, but actually what I wanted was to resolve this situation that can appear on several other types of sites.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if the situation is the same at other types of sites, the solution is the same: the site recognizes you are accessing it from mobile. it has an app for mobile. it issues directives that cause the device to launch the app. the site is not meant for webview. or the site has not written a version suitable for webview. if you insist on using webview and can trick the site into thinking you are not using a webview, you will get what you get. in this case, the audio can be heard (which, presumably, is what somebody accessing the site wants in the first place).

if the situation is different at other types of sites, the solution will be different.
 
Upvote 0
Top