基本的内部链接不会在蜂窝应用工作?会在、蜂窝、基本、链接

2023-09-04 11:06:32 作者:画扇浅醉染一袭

内部环节似乎并不在我的出版应用程序是工作在Android版本3。我的应用程序的目标Froyo的在这一点上。

该应用程序工作正常万吨电话,但我的新的Galaxy Tab无法处理的内部链接!它可以在HTML页面内处理它们,即:

 < A HREF =#帮助>转到FAQ< / A> <! - 去FAQ链接 - >
 

转到标记在同一页上降低:

 <名称=常见问题解答ID =常见问题解答>< / A>
 

不过从另外一个HTML文件,即索引页,该链接不再蜂窝作品:

 < A HREF =mainpage.html#常见问题解答>常见问题< / A> <! - 转到错误页面 - >
 
PPT 蜂窝车联 C V2X 工作组,促进跨行业融合创新

另外,如果我去一个内部链接,并从那里通过链接到另一个网页,然后点击返回按钮,(这是重载去previous的WebView页)你得到同样的错误,即:

 的网页的文件:///android_asset/folder/mainpage.html#faq可能暂时无法连接,或者它已永久性地移动到新网址
 

WTF! web视图只是在页面上,但你打回1秒后,它不能找到它。也可以从另一个HTML页面链接,但是这一切工作正常,在1.x中,2.X,只是没有3.1(有没有试过3.0)

注:我已经看到了这几乎相同的问题: android_asset不工作的蜂窝? 但也有我的资产路径中没有空格。

我曾尝试使用和不使用Web客户端,并试图在DOM和缓存设置无济于事。下面是我目前在OnCreate中的一个例子:

 浏览器=新的WebView(本);
//浏览器=(web视图)findViewById(R.id.webkit); //试着用XML和无
    browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    browser.getSettings()setJavaScriptEnabled(真)。
    browser.getSettings()setPluginsEnabled(真)。
// browser.getSettings()setJavaScriptCanOpenWindowsAutomatically(真正的);
// browser.getSettings()setUseWideViewPort(真)。
    browser.setBackgroundColor(Color.parseColor(#333333));
    browser.setInitialScale(1);
    。browser.getSettings()setBuiltInZoomControls(真正的);


    最后活动MyActivity =这一点;
    browser.setWebChromeClient(新WebChromeClient(){

        公共无效onProgressChanged(web视图来看,INT进度){
            //使栏消失加载URL后,变化
            //字符串数据加载中...

            setProgressBarIndeterminateVisibility(真正的);

            MyActivity.setTitle(加载。+ +的进展%);
            MyActivity.setProgress(进度* 100); //使酒吧

            如果(进度== 100){
                的setTitle(APP标题内容十分重要);
                setProgressBarIndeterminateVisibility(假);
            }
        }
    });
    browser.setWebViewClient(新WebViewClient(){
        @覆盖
        公共无效onReceivedError(web视图来看,INT错误code,字符串描述,字符串failingUrl)
        {
            //处理错误
        }

        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
        {
            view.loadUrl(URL); //注意我试过有和没有覆盖这
            返回true;
        }

    });
    的setContentView(浏览器);

    browser.loadUrl(文件:///android_asset/folder/page.html);
 

解决方案

下面是我的解决方法code这样的错误是对用户透明。 定义 WebViewClient 的浏览器,包括类似下面的onReceivedError

  @覆盖
    公共无效onReceivedError(web视图来看,INT错误code,字符串描述,字符串failingUrl)
    {
        如果(failingUrl.contains(#)){
            Log.v(日志,失败的URL:+ failingUrl);
            最终诠释sdkVersion =的Integer.parseInt(Build.VERSION.SDK);
            如果(sdkVersion> Build.VERSION_ codeS.GINGERBREAD){
                的String []温度;
                临时= failingUrl.split(#);
                view.loadUrl(温度[0]); //负荷无内部链接页面

                尝试 {
                    视频下载(400);
                }赶上(InterruptedException异常E){

                    e.printStackTrace();
                }
            }

            view.loadUrl(failingUrl); // 再试一次
        } 其他 {
             view.loadUrl(文件:///android_asset/tableofcontents.html);
        }
    }
    });
 

此招数的WebView先加载网页没有#LINK,然后睡一秒钟。4,然后再加载完整的URL。我选择只有sdkVersion做这一招的平板电脑。如果有任何其他的错误我打开另一个网页,该tableofcontents.html。这适用于固定在我的Galaxy Tab的问题。

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

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>  

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 -->

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! 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)

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

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");

解决方案

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");
        }
    }
    });

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.