“你好,WebView"教程在 Android 浏览器中打开请求的地址,而不是在我的 webview 中 [英] "Hello, WebView" tutorial opens the requested address in Android browser and not in my webview

查看:16
本文介绍了“你好,WebView"教程在 Android 浏览器中打开请求的地址,而不是在我的 webview 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 Android 2.1 AVD 的 Android 模拟器,但我遇到以下问题:尝试使用 webView.loadUrl 在 WebView 中加载 URL 会导致它在浏览器中打开.

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.

注意:我说的是初始打开,不是在浏览器中打开来自 WebView 的链接的问题,不过,也许它以某种方式连接.

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.

我尝试了几件事:

  • 我已从清单中删除了 <uses-permission android:name="android.permission.INTERNET"/>.这实际上使它正常工作,即将 html 加载到 webview 中.然而,正如人们所料,它加载的唯一内容是无法连接互联网"错误页面.
  • 我已经调试了该项目以确保确实在 loadUrl 函数中,它打开了 Android 浏览器.此时的 CatLog 如下所示:
  • 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:信息/活动管理器(51):启动活动:意图{行为=android.intent.action.VIEWcat=[android.intent.category.BROWSABLE]dat=http://m.walla.co.il/ErrorPage.aspx?ReturnUrl=/Default.aspxcmp=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 }

  • 我试过下载一个真正的示例 项目(《Hello Android》一书源文件,项目——BrowserView).然而,它并没有完全一样.
  • 我创建了一个新项目并按照 Google 的 official使用 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 可能具有重定向.重定向的行为类似于链接点击,默认情况下会在浏览器中打开.确保您访问的 URL 没有重定向(例如 HTTP 301 响应),或使用 WebViewClientshouldOverrideUrlLoading() 来捕获这些并将它们重新路由回来到 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.

      这篇关于“你好,WebView"教程在 Android 浏览器中打开请求的地址,而不是在我的 webview 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆