Android中的WebChromeClient打开一个静态的HTML页面URL中一些人物被添加 [英] Opening an static html page in WebChromeClient in Android gets added with some more characters in url

查看:740
本文介绍了Android中的WebChromeClient打开一个静态的HTML页面URL中一些人物被添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正误差在文件的Web页:///#/android_asset/webpage.htm无法加载为:是一个目录在模拟器。

但我的code是 webView.loadUrl(文件:///android_asset/webpage.htm);

首先,页面呈现完美,但再次渲染后刷新页面,并不会被加载,将获得该网页无法使用。
如果我们能仔细看已经由Android模拟器给出了链接有android_asset前两个额外的字符。

First the page renders perfectly but again after rendering refreshes the page and does not get loaded and will get the web page not available. If we could carefully see the url that has been given out by the android emulator there are two extra characters before android_asset.

下面是code。

public class Catalog extends Activity {
final Activity activity = this;
WebView webView;
 ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);//used for rendering percentage of loading 
setContentView(R.layout.catalog_layout);

try{

    webView = (WebView) findViewById(R.id.browserwebview);
    webView.getSettings().setJavaScriptEnabled(true);

     webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgressBarVisibility(true);
                activity.setProgress(progress * 100);

                if(progress == 100){
                    activity.setTitle(R.string.app_name);

                }

            }

        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                Toast.makeText(activity, "Oh no!"+ description, Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onLoadResource (WebView view, String url) {


            }




            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {


                return true;
            }


        });





        webView.loadUrl("file:/android_asset/web/webpage.html");


}
catch (Exception e) {
    e.printStackTrace();
}


ImageButton btnBack = (ImageButton)this.findViewById(R.id.buttonBackCatalog);
btnBack.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        if(webView.canGoBack()){
             webView.goBack();
        }else{
            Intent myIntent = new Intent(view.getContext(), FCFActivity.class);`
           `startActivityForResult(myIntent, 0);
        }


    }


});


/*
 * Actions for footer Buttons
 * 
 */

ImageButton buttonFooterMainHome = (ImageButton)findViewById(R.id.footerMainBtnHome);
buttonFooterMainHome.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), FCFActivity.class);
        startActivityForResult(myIntent, 0);

    }
});


LinearLayout homeLinearLayout=(LinearLayout)this.findViewById(R.id.footerLayoutHome);
homeLinearLayout.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), FCFActivity.class);
        startActivityForResult(myIntent, 0);

    }
});






}
     @Override
    public void onConfigurationChanged(final Configuration newConfig)
    {
        // Ignore orientation change to keep activity from restarting
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){

        }

    }
}

期待您的回复。

感谢。

推荐答案

哦,这令我头疼,他们改变了它的工作原理为Android版本之一,但不记得是哪。这是我做的:

Oh this caused me headaches, and they changed how it worked for one of the android versions, but can't remember which. Here is what I do:

webView.loadUrl("file:/android_asset/webpage.html");

如果你的静态网页有图像,您使用此链接:

and if your static webpage has images you use this link:

file:///android_asset/yourimage.png

编辑试试这个: http://stackoverflow.com/a/8737547/969325 ,清洁工程和检查资源文件是在路径。

Edit try this: http://stackoverflow.com/a/8737547/969325, clean project and check if asset file is at path.

这篇关于Android中的WebChromeClient打开一个静态的HTML页面URL中一些人物被添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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