Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell if android user came from home screen app

Is there a way to tell if a user came to your website via a home screen shorcut? With iOS I'm able to use the following javascript code to detect if the user opened the page via the home screen shortcut:

if (('standalone' in navigator && !navigator.standalone && (/iphone|ipod|ipad/gi).test(navigator.platform) && (/Safari/i).test(navigator.appVersion)) {
            window.location = 'index2.html';
        }

i can't find that there is anything similar that you can do with android though. any help would be greatly appreciated :)

like image 349
skrilled Avatar asked Mar 22 '13 00:03

skrilled


3 Answers

The short answer is "No."

A web site bookmark widget launched from the Android homescreen does not include a referer (I just checked).

Furthermore, the mechanism for installing/bookmarking a web app locally on Android is completely different than on the iPhone, and definitely not as full featured (as reported on the issue tracker).

[...]

I expressly endorse this request, as it is not possible to offer a native-looking WebApp in Android at the time without implementing a shallow hull of an App, containing just a WebView (or implementing one of the popular Frameworks like PhoneGap or apparat.io).

This leads to the point where you have to pay 25 USD for offering a native-looking WebApp on Android. The same thing is free on iOS devices - and more elegant

By the way, the web site owner above is slightly wrong. In android, he could just offer the app from his web site without paying the $25 to go through the Market/Google Play since Android uses free self-signing certificates. Thought, his main point remains. That is not an easy thing to do and the end result may not be very usable unless he puts a lot of work into it.

And comparatively speaking, I'd say that on Android, its stripped-down bookmark widget homescreen functionality, compared to iOS, is almost never used.

For instance, I personally use the main chrome browser, or google search, or an existing app, as my main entry points into any of the web sites I visit.

In the screenshot above, the three red bookmarks on the left are actually web bookmarks. And just to contrast them with non-web bookmark widgets that I actually like, I've also placed two ebook widgets on the right.

Also, I consider myself a power user and an avid early adopter of many features, and I do use some of the less used Android widgets, but according to HTC, I'm only part of 10% of people who do so (unless it's for weather, clock(s), or music, which apparently people do use when they first set up their phone!?).

And even for me, someone who loves Android widgets (especially on my Android tablet), the larger bookmarks manager widget gives me too little control to be attractive to me, and the single web site bookmark widget, which gives decent control, doesn't look very good to me and I never use it since it's just a red bookmark with a tiny favicon embedded in the middle of it.

In any case, coming back to your original question.

Short of writing a small utility that each Android user of your site would willingly install on his/her device. Your only alternative would be to try to intervene when the user tries to bookmark your site. And intervening would work only as in so far as the user doesn't try to clean the bookmark of any of the url arguments appended to it when he sets it. For instance, you could append the date the user is currently browsing your site to a url, and if the user bookmarked that url, that same url might appear at a much later date. That would be one way of trying to see if the user came from a bookmark (or a saved link some place).

But even if you could do that, that would only tell you if the user came to your site via a history bar autocomplete, or via a homescreen initiated bookmark, or just via a normal Chrome initiated bookmark, instead of just typing the address straight in (I'm not mentioning google search, because with the user using google search, google would give you the referer at least).

like image 188
Stephan Branczyk Avatar answered Sep 28 '22 09:09

Stephan Branczyk


Since shortcuts created on the home screen use the same intent as any other app (after all, a launcher is still an app), this is impossible.

However, if you've created the shortcut by yourself, you can set the URL to a different one and by this to know that it could be from the launcher.

Also, if the app you've made can be like a pipe between the launcher and the web, you can set the intent to reference to the app and by this you could assume that the link was opened from the launcher.

like image 26
android developer Avatar answered Sep 28 '22 09:09

android developer


I'll go with the short answer stated before: No.

Android Browsers won't let any website access information about the INTENT used to open the browser or other stuff due to JS security constraints.

But... wait... there is a way to bind JavaScript on a Website to Android code (http://developer.android.com/guide/webapps/webview.html#BindingJavaScript), so what I would do, given that the website is already developed, is to develop a simple Android App with a nice icon and a WebView with JS enabled and pointing to the Website, so it serves as a client or wrapper App to let's say... "http://thewebsite.com?client=android". On the WebView, you can block navigation to other sites, so the user can't go anywhere else, user will have to use your site navigation. Then you can bind Android code to JavaScript as mentioned above to expose methods from the Android environment to the JavaScript in your Website.

Instead of letting people add a shortcut to your Website, give them a link to download your little wrapper App from the Google Play Store. That way, you'll know who is using your Website/WebApp from Android devices, and since you own the App, you can access the INTENT and know Android OS information, and get more stuff about the device from the JS in your site than the UserAgent would give you, like to know if there is an active network connection on the client, etc.

Good luck!

like image 31
Oscar Salguero Avatar answered Sep 28 '22 11:09

Oscar Salguero