Android WebView loading dropbox shortened URLs
I am making an application that creates and allows the user to edit an HTML file by adding notes and / or links to it. It then allows the user to sync it via dropbox so that they can view the file from any other Android device, or from a browser on their computer. In this program I have a WebView which loads the html page and shows it to the user. However if I tell the webview to load the shortened version of the URL(E.g. http://db.tt/DrSmhwq) instead of putting it inside my WebView it opens it in the browser on top of my app. If I use the long version of the URL(E.g. http://dl.dropbox.com/u/5724095/DBNotes.html) it loads it inside my WebView just fine. So I have a few questions: What is the difference between the shortened URLs and the long ones? Is there something about the URL that is causing this behavior, or is it more likely that this is an issue with the Android WebView? And does anyone know if there a way to generate the long versions of the URLs from within the dropbox Android app? Otherwise I am going to have to direct my users to go to the website on their computer and generate the long link and type it in to m开发者_Python百科y app, this does not seem like a good solution.
Edit: I made a bitly url that points to the longer dropbox url and tried to call wv.loadUrl() on that, it also opened up the browser instead of loading it into the WebView. So I am guessing that this is the default behavior for how the WebView handles redirects. Does anyone know how I can make it load the page that its directed to inside itself instead of a browser window?
What is the difference between the shortened URLs and the long ones?
The server is issuing a redirect, which you are not handling, so the default WebView
behavior is invoked -- open the new URL in the browser.
Does anyone know how I can make it load the page that its directed to inside itself instead of a browser window?
Implement a WebViewClient
, particularly shouldOverrideUrlLoading()
, to handle the redirect. Attach an instance of your WebViewClient
to your WebView
via setWebViewClient()
.
精彩评论