"你好,的WebView"教程将打开Android浏览器,而不是在我的WebView所请求的地址我的、是在、而不、你好

2023-09-13 01:02:07 作者:ヤo最爱冰淇淋∩_∩

我使用的Andr​​oid模拟器与Android 2.1的AVD,我有以下问题:试图加载使用一个web视图的URL的 webView.loadUrl 使其在浏览器中,而不是打开。

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.

请注意:我说的是最初的开放,不可以中,在浏览器链接从web视图打开的问题,不过,也许是某种联系

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.

我已经试过几件事情:

在我删除 &LT;使用-权限的Andr​​oid:名称=android.permission.INTERNET对/&GT; 从清单。这实际上是由它正常工作,即加载HTML到web视图。然而,正如人们所期望的那样,它装载的唯一事情是无法连接互联网错误页面。 在我调试的项目,以确保确实位于使用loadURL 的功能,它会打开Android浏览器。在这一点上的目录下载是这样: 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:   信息/ ActivityManager(51):启动   活动:意向{   ACT = android.intent.action.VIEW   猫= [android.intent.category.BROWSABLE]   DAT = HTTP://m.walla.co.il/ErrorPage.aspx RETURNURL = / Default.aspx的   CMP = com.android.browser / .BrowserActivity   }

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 } 在我试图下载一个真正的样品项目(你好Android的书源文件,项目 - BrowserView中)。但是,它没有工作一样。 在我创建了一个新的项目,随后在谷歌的官方教程使用的WebView,得到了相同的结果。

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?

谢谢, 维塔利

推荐答案

您尝试可能访问URL有重定向。重定向行为类似于链接的点击次数和在默认情况下,在浏览器中打开。请确保您正在访问不做重定向(例如HTTP 301响应),或使用 WebViewClient shouldOverrideUrlLoading()来捕捉这些和重新路由他们带回的WebView。

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.