基本的内部链接在蜂窝应用程序中不起作用? [英] Basic internal links don't work in honeycomb app?

查看:22
本文介绍了基本的内部链接在蜂窝应用程序中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我发布的应用程序中,内部链接在 Android 版本 3 中似乎不起作用.我的应用此时面向 Froyo.

Internal links do not seem to be working in Android version 3 in my published app. My app targets Froyo at this point.

该应用程序在大量手机上运行良好,但我的新 Galaxy Tab 无法处理内部链接!!它可以在一个 html 页面中处理它们,即:

The app works fine on tons of phones, but my new Galaxy Tab can't handle the internal links!! It can handle them within an html page, ie:

<a href="#faq">Go to faq</a>  <!-- goes to FAQ link -->

转到同一页面下方的标签:

Goes to the tag lower on the same page:

<a name="faq" id="faq"></a>  

然而,从另一个 html 文件,即索引页面,该链接在 Honeycomb 中不再有效:

However from a another html file, ie the index page, the link no longer works in Honeycomb:

<a href="mainpage.html#faq">FAQ</a>  <!-- goes to error page -->

另外,如果我转到一个内部链接,然后从那里跟随一个链接到另一个页面,然后点击后退按钮,(它被覆盖以转到上一个 webview 页面)你会得到同样的错误,即:

Also, if I go to an internal link, and from there follow a link to another page, then hit the back button, (it is overridden to go to previous webview page) you get the same error ie:

The webpage at file:///android_asset/folder/mainpage.html#faq might be temporarily    down or it may have moved permanently to a new web address

WTF!webview就在页面上,但是你1秒后回击,它找不到它.它也不能从另一个 html 页面链接,但它在 1.x、2.x 中一切正常,只是不是 3.1(没有尝试过 3.0)

WTF! The webview was just on the page, but you hit back 1 second later, and it can't find it. Nor can it link from another html page, but it all works fine in 1.x, 2.x, just not 3.1 (have not tried 3.0)

注意:我见过这个几乎相同的问题:android_asset 不适用于 Honeycomb?但是我的资产路径中没有空格.

NOTE: I have seen this almost identical question: android_asset not working on Honeycomb? But there are no spaces in my asset path.

我尝试过使用和不使用网络客户端,并尝试过 DOM 和缓存设置无济于事.这是我目前在 oncreate 中拥有的示例:

I have tried with and without the webclient, and tried the DOM and cache settings to no avail. Here is an example of what I currently have in oncreate:

        browser = new WebView(this);
//  browser = (WebView) findViewById(R.id.webkit);  // tried with XML and without
    browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.getSettings().setPluginsEnabled(true);
//  browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//  browser.getSettings().setUseWideViewPort(true);
    browser.setBackgroundColor(Color.parseColor("#333333"));
    browser.setInitialScale(1);
    browser.getSettings().setBuiltInZoomControls(true);


    final Activity MyActivity = this;
    browser.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            // Make the bar disappear after URL is loaded, and changes
            // string to Loading...

            setProgressBarIndeterminateVisibility(true);

            MyActivity.setTitle("  Loading . . . " + progress + "%");
            MyActivity.setProgress(progress * 100); // Make the bar

            if (progress == 100) {
                setTitle("  APP TITLE YADA YADA");
                setProgressBarIndeterminateVisibility(false);
            }
        }
    });
    browser.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);  // note I tried with and without overriding this 
            return true;
        }

    });
    setContentView(browser);

    browser.loadUrl("file:///android_asset/folder/page.html");

推荐答案

这是我的解决方法代码,因此该错误对用户是透明的.
为浏览器定义 WebViewClient,并为 onReceivedError 包含如下内容:

Here is my workaround code so the bug is transparent to the user.
Define the WebViewClient for the browser, and include something like the following for onReceivedError:

        @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
    {
        if (failingUrl.contains("#")) {
            Log.v("LOG", "failing url:"+ failingUrl);
            final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
            if (sdkVersion > Build.VERSION_CODES.GINGERBREAD) {
                String[] temp;
                temp = failingUrl.split("#");
                view.loadUrl(temp[0]); // load page without internal link

                try {
                    Thread.sleep(400);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
            }

            view.loadUrl(failingUrl);  // try again
        } else {
             view.loadUrl("file:///android_asset/tableofcontents.html");
        }
    }
    });

这会欺骗 webview 首先加载没有 #link 的页面,然后休眠 0.4 秒,然后再次加载完整的 URL.我选择仅通过 sdkVersion 为平板电脑执行此技巧.如果有任何其他错误,我会加载另一个页面,tableofcontents.html.这可以解决我的 Galaxy Tab 上的问题.

This tricks the webview to first load the page without the #link, then sleep for .4 of a second, and then load the full URL again. I have chosen to do this trick for tablets only by sdkVersion. If there is any other error I load another page, the tableofcontents.html. This works to fix the problem on my Galaxy Tab.

这篇关于基本的内部链接在蜂窝应用程序中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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