如何在android中检测webview或浏览器

I'm going to detect webview or browser in android I want to display a banner in Android browsers. Which users click to install app. And I do not want to display this banner on the webview android.

I use this:

    <?php
     if ($_SERVER['HTTP_X_REQUESTED_WITH'] == "app.mypackage") {
      echo 'WebView'; }
      else {
     echo 'no-WebView';
     }
   ?>

But that does not work, and displays the 'webview' in browser and webview app

There is another way to do this?

Not accurate but you could use Javascript to check the platform that the site is running on using:

navigator.platform

Possible result(s) of using this property will include:

  • HP-UX
  • Linux i686
  • Linux armv7l (Android)
  • Mac68K
  • MacPPC
  • MacIntel
  • SunOS
  • Win16
  • Win32
  • WinCE