Android开发向useragent添加自定义字符串

时间:2015-05-14 06:46:35

标签: android webview

我正在尝试将自定义HTTP标头添加到我的Android应用程序的webView中,以验证webView是否从我们的应用程序运行。

当我们使用webView.getSettings时,它始终显示错误消息。

Android.WebKit.Webview does not contain a defenition for getSettings()

这是我们的代码:

using Android.App;
using Android.OS;
using Android.Webkit;
using Android.Widget;
using Android.Views;

namespace LoadWebPage {
[Activity(Label = "LoadWebPage", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity {
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView (Resource.Layout.Main);

        WebView webView = FindViewById<WebView>(Resource.Id.LocalWebView);
        webView.SetWebViewClient (new WebViewClient ());
        WebSettings settings = webView.getSettings();
        webView.Settings.JavaScriptEnabled = true;

        webView.LoadUrl("http://www.google.nl");


        webView.Settings.BuiltInZoomControls = false;
        webView.Settings.SetSupportZoom(true);    
        Window.AddFlags(WindowManagerFlags.Fullscreen);
        Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);


        };

    }

}
}

感谢。

1 个答案:

答案 0 :(得分:0)

此解决方案解决了我们的问题。

string standard_agent = webView.Settings.UserAgentString;
webView.Settings.UserAgentString = standard_agent + "NEWUSERAGENT";