0

I used AppsGeyser to create the Android version of my web app.

I'd like the web app to show an Android button linking to the app on Googleplay, but not show it on the web-app version.

I'm unsure how to do this, since Appsgeyer needs to use my web app to build the Android app.

Is there HTML or other code I can use to check if this is the Android or web app, and display accordingly?

Thanks for your time and help.

Shaun
  • 2,043
  • 3
  • 27
  • 36

1 Answers1

2

Check UserAgent in javascript. Here's a solution of how to detect mobile browsers.

It can be shortened to something like

if (navigator.userAgent.match(/Android/i)) {
    showButton();
}
Community
  • 1
  • 1
  • Thanks Alexander - I will try this out now mate. – Shaun Mar 20 '14 at 06:18
  • Just to clarify - the above won't be true if it's an Android app, only if it's a browser on an Android phone, right? – Shaun Mar 20 '14 at 07:59
  • Should work both for Android browser and WebView, which is used by AppGeyser to display content. – Alexander Sukharev Mar 20 '14 at 08:20
  • Ahh - I don't think it will do what I need then then, which is - if it's a browser (desktop or Android), display the Android button to download the app, but if it's the Android app, don't display it. There code you gave me worked for checking the platform no probs though - cheers. – Shaun Mar 20 '14 at 13:33
  • Finally, I get it. :) How's about writing the Android application by yourself instead of using AppGeyser? It should be very simple: just one Activity with WebView in it. There you can assign own specific UserAgent and then check it in javascript. http://developer.android.com/reference/android/webkit/WebSettings.html#setUserAgentString(java.lang.String) – Alexander Sukharev Mar 20 '14 at 18:57
  • AppsGeyser has a setting where you can change the useragent of your app (doesn't change the web-app source code, just the Android app). I tested it by making my user agent "test", and then put alert(navigator.userAgent); in the web-app source. It displays "test" in my Android app. This could be a way for me to id the app, but I'm wondering -will changing the user agent like this affect how it's displayed? If not, this could be a good way to not only id the app, but also add a version number, so you can display a pop up if you have an update available. – Shaun Mar 26 '14 at 13:40
  • Sorry for the late response. Changing the user agent shouldn't produce any negative outcome. Only if your app or dependent libraries use it for any other reason. You also can define it following the [commonly used format](http://en.wikipedia.org/wiki/User_agent#Format_for_human-operated_web_browsers) so at least general system information will be preserved. – Alexander Sukharev Apr 07 '14 at 14:08
  • Thanks Alexander - I will look at this today. – Shaun Apr 08 '14 at 00:16