android user agent

前端 未结 5 899
旧巷少年郎
旧巷少年郎 2020-11-30 01:22

I am writing an app in Android that uses a WebView to display HTML content. I was told to get an Android user agent for my app - how do I do that? I opened http://whatsmyuse

5条回答
  •  情话喂你
    2020-11-30 01:36

    Put this in the onCreate method of the java class for the activity that displays the WebView:

    WebView myWebView = (WebView)findViewById(R.id.webview);
    //get the UA of the current running device:
    String userAgent = view.getSettings().getUserAgentString() ;
    //set the UA of the webview to this value:
    myWebView.getSettings().setUserAgentString(userAgent);
    

    Don't use System.getProperty("http.agent") - this will return the 'Dalvik' user agent (Dalvik is the VM that individual Android apps run within)

提交回复
热议问题