0

I am developing a web application in which, once the user has successfully logged in the browser type should be detected. If the page was opened on an Android phone the user should be able to download an APK file. On iOS however a link to the app in the AppStore should be presented.

Matthias Steinbauer
  • 1,641
  • 9
  • 23
  • Thanks for replying ..:)Detecting mobile OS,I got but I also wanted to know if we can programmaticaly download the apk file i.e Once it is detected that OS is android then app must be install in user android mobile..I am still not getting any solution. – user1577535 Feb 02 '15 at 09:44
  • you can do a ```window.open(apkURL)```, it ll try and download the apk to his phone, but dont think yo can force him to install it, another option(better one) redirect to the play store. – mido Feb 02 '15 at 09:59
  • Okay ,I will try doing it with redirect to play store . – user1577535 Feb 02 '15 at 12:35

1 Answers1

0

This is actually quite easily achieved through browser detection. Include jQuery to your page and try the following:

$(document).ready(function() {
    var ua = navigator.userAgent.toLowerCase();
    var android = ua.indexOf("android") > -1;
    var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
    if(android) {
        $('#androidLink').show();
    }
    if(iOS) {
        $('#iosLink').show();
    }
});

Assuming you have something like this in your HTML page:

<div id="androidLink" style="display:none;">
   Hi Android user <a href="link.to.apk">click here to download our app</a>
</div>
<div id="iosLink" style="display:none;">
   Hi iOS user  <a href="link.to.apple.app.store">click here to download our app</a>
</div>
Matthias Steinbauer
  • 1,641
  • 9
  • 23
  • Thanks for reply..I could detect the mobile os as well as I could download the apk file.Just for more info for downloading apk..change the configuration in Mime.type which in apache/etc/mime.type as:application/vnd.android.package-archive with extension apk. and paste your apk file to root folder of web server to access the apk on click of href. – user1577535 Feb 06 '15 at 10:15