本文介绍了如何使用web视图作为Android应用程序浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在我的应用程序的WebView加载上面的URL将其更改为但是,当我的网址加载相同的URL在浏览器。

有没有办法在我的应用程序的WebView加载正常的网址()不加载页面移动()

有人知道,请帮助我

  go.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                如果(Searchtext.getText()。的toString()。equalsIgnoreCase()){                    alertDialog =新AlertDialog.Builder(OnlineRecipe.this)
                            。创建();
                    alertDialog.setTitle(信息);
                    alertDialog.setMessage(请输入一些字);                    alertDialog.setButton(OK,
                            新DialogInterface.OnClickListener(){
                                公共无效的onClick(DialogInterface对话框,
                                        其中INT){
                                    //在这里写下您的code后执行
                                    //对话框关闭
                                    alertDialog.dismiss();
                                }
                            });                    //显示警报信息
                    alertDialog.show();
                }其他{                    字符串URL =htt​​p://allrecipes.com/search/default.aspx?qt=k&wt=
                            + Searchtext.getText()。的toString()
                            +&放大器; RT = R&安培;起源=食谱搜索结果;
                    webview.getSettings()setJavaScriptEnabled(真)。
                    webview.loadUrl(URL);
                }            }
        });


解决方案

如果我理解正确的话,所有你想要做的是负载在桌面模式下的WebView ...如果是这样的话,请使用以下code,以得到它的工作:

  webview.getSettings()setUserAgentString。(Mozilla的/ 5.0(Windows NT的6.2; WOW64)为AppleWebKit / 537.31(KHTML,像壁虎)的Chrome / Safari的20 / 537.31);

此只需要放置在code就在你创建的WebView对象后的部分,网页流量。

编辑:只要你知道以供将来参考,这条线code变化的用户代理的网站欺骗,以为你是从一台计算机访问它,而不是一个电话

URL HERE

When I load the above url in my application webview it change as http://m.allrecipes.com But when i load the same url in a browser its url as http://allrecipes.com.

Is there any way to load normal url(http://allrecipes.com) in my application webview without loading page for mobile(http://m.allrecipes.com)

Anybody Know please help me

go.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (Searchtext.getText().toString().equalsIgnoreCase("")) {

                    alertDialog = new AlertDialog.Builder(OnlineRecipe.this)
                            .create();
                    alertDialog.setTitle("Message");
                    alertDialog.setMessage("Please Enter Some Word");

                    alertDialog.setButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    // Write your code here to execute after
                                    // dialog closed
                                    alertDialog.dismiss();
                                }
                            });

                    // Showing Alert Message
                    alertDialog.show();
                } else {

                    String url = "http://allrecipes.com/search/default.aspx?qt=k&wt="
                            + Searchtext.getText().toString()
                            + "&rt=r&origin=Recipe Search Results";
                    webview.getSettings().setJavaScriptEnabled(true);
                    webview.loadUrl(url);


                }



            }
        });
解决方案

If I understand correctly, all you want to do is load http://allrecipes.com in your WebView in desktop mode... If that is the case, use the following code to get it to work:

webview.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/20 Safari/537.31");

This only needs to be placed in your code right after the part where you create the WebView object, webview.

EDIT: just so you know for future reference, this line of code changes the user agent to trick the website into thinking you're accessing it from a computer instead of a phone.

这篇关于如何使用web视图作为Android应用程序浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:24
查看更多