views:

790

answers:

3

Hi everyone,

I am using Android emulator with AVD of Android 2.1 and I have the following problem: Trying to load a URL in a WebView using webView.loadUrl causes it to open in the browser instead.

Note: I am talking about the initial opening, not the issue in which links from the WebView open in a browser, though, perhaps it is somehow connected.

I've tried several things:

  • I've removed <uses-permission android:name="android.permission.INTERNET" /> from the manifest. That actually made it work correctly, i.e, load the html into the webview. However, as one would expect, the only thing it loaded is "unable to connect the internet" error page.
  • I've debugged the project to make sure and indeed at loadUrl function, it opens Android browser. The CatLog at this point is as such:

05-23 22:54:06.858: INFO/ActivityManager(51): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=http://m.walla.co.il/ErrorPage.aspx?ReturnUrl=/Default.aspx cmp=com.android.browser/.BrowserActivity }

  • I've tried downloading a real sample project ("Hello Android" book source files, project - BrowserView). However, it didn't work just the same.
  • I've created a new project and followed the directions at Google's official tutorial of using WebView and got the same result.

I haven't find anyone else complaining about it. Why does it happen?

Thanks, Vitaly

+6  A: 

The URL you are trying to visit probably has a redirect. Redirects behave like link clicks and will by default open in the Browser. Make sure the URL you are visiting does not do a redirect (e.g., HTTP 301 response), or use WebViewClient and shouldOverrideUrlLoading() to catch these and re-route them back to the WebView.

CommonsWare
Oh. That makes sense. I'll check.
VitalyB
Yes, you were right. Thanks!
VitalyB
A: 

yaa i have done WebViewClient and shouldOverrideUrlLoading() but for me it is not displaying any thing on screen, even i debugged application and its not giving any exception, please give me some idea to do it.

Reddy
Asking new questions in the answers section is never going to get your problem solved. Start a new question and people can help you
HXCaine
A: 

Hi,

If have the same problem with multiple redirects, if I made some changes(overwrite) shouldOverrideUrlLoading() then is my webview not displaying any thing, the screen is empty.

I want to show a loading dialog until the last/final URL is loaded, and only then to hide this progressdialog.

Can somebody help me?

Thanks, Lorand.

Lorand
You should create a new question and ask it there, you have a lot more chance to get it answered that way. If you think this question is also relevant, then go ahead and add a link to it in the new question.
VitalyB