Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can totally do that and at developer.android.com suggest it as well, when they talk about the WebView, especially if you want to build a web app for your web view. Reference here: <a href="http://developer.android.com/guide/webapps/webview.html" rel="nofollow noreferrer">http://developer.android.com/guide/webapps/webview.html</a></p> <p>Id suggest not only to keep reference to the application in your User Agent but to also keep track of the version as well.</p> <p>Anyways, I was looking to change my UA too and the discussions here and the encouraged me to do so as well.</p> <p>Here is my implementation:</p> <p><strong>On your Android APP:</strong></p> <pre><code>String versionName=""; int versionCode=0; try { versionName = getBaseContext().getPackageManager().getPackageInfo(getBaseContext().getPackageName(), 0 ).versionName; versionCode = getBaseContext().getPackageManager().getPackageInfo(getBaseContext().getPackageName(), 0 ).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } </code></pre> <p>If you want to auto increment the build number aka. versionCode you may take a look to this other <a href="https://stackoverflow.com/a/8156809/969132" title="Stack Overflow">Stack Overflow</a> post as well, the C# solution.</p> <p>Afterwards you just change the User Agent.</p> <pre><code>WebView mywebview = (WebView)findViewById(R.id.webView); String myUserAgent = " MyFancyAPPName V."+versionName+"."+versionCode; mywebview.getSettings().setUserAgentString(mywebview.getSettings().getUserAgentString()+myUserAgent); </code></pre> <p><strong>On your Web Application: In PHP</strong></p> <pre><code>&lt;?php $ua = strtolower($_SERVER['HTTP_USER_AGENT']); if(stripos($ua,'MyFancyAPPName') !== false){ //do whatever you wish here } ?&gt; </code></pre> <p><strong>Or In JavaScript</strong></p> <pre><code>var ua = navigator.userAgent.toLowerCase(); var isAndroid = ua.indexOf("MyFancyAPPName") &gt; -1; if(isAndroid) { //do whatever you wish here } </code></pre> <p>Or you can directly detect it from the <strong>.htaccess</strong> file:</p> <pre><code>RewriteCond %{HTTP_USER_AGENT} ^.*MyFancyAPPName.*$ RewriteRule ^(.*)$ http://www.MyWebSite/MyFancyAPPName [R=301] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload