1

我正在应用程序的注册模块中工作,使用返回TinyURL与新用户对应的生成的 Web 服务。这TinyUrl为用户提供了对平台的访问权限,由WebView.

问题:WebView方法适用于任何 URL,但不适用于 TinyURL. 在TinyURL其他浏览器上运行良好。我错过了什么?

Java的定义和配置WebView

WebView browser = (WebView) findViewById(R.id.wvBrowser);
WebSettings webSettings = browser.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowContentAccess(true);
    browser.setWebViewClient(new WebViewClient());
    browser.loadUrl(myTinyUrl);

的 XML 定义WebView

<WebView
    android:id="@+id/wvBrowser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

感谢您的时间和帮助。欢迎提出任何建议。

4

2 回答 2

1

WebViewURL 应以http://或开头https://。以 开头的 URLwww...通常显示标准的 Android 404 页面。

于 2014-05-23T09:00:13.137 回答
1

您可以在加载之前使用此方法修复 URL 错误,例如http://或:www...

/**
 * fix the URL by adding missing "www." and "http://"
 * 
 * @param url
 * @return fixed url
 */
public static String fixUrl(String url) {
    if (!(url == null || url.length() == 0)){
        if (!url.startsWith("www.") && !url.startsWith("http://")) {
            url = "www." + url;
        }
        if (!url.startsWith("http://")) {
            url = "http://" + url;
        }
    }
    return url;
}
于 2014-05-23T09:08:10.343 回答