Book Image

Sencha Touch Cookbook

By : Ajit Kumar
Book Image

Sencha Touch Cookbook

By: Ajit Kumar

Overview of this book

Sencha touch is a versatile HTML5-based framework for developing mobile web apps that look and feel native on touch screen devices, and with it you can write your code once and deploy it to both iOS and Android saving you both time and money. The Sencha touch cookbook has a comprehensive selection of recipes covering everything from installation right through to HTML5 geo location. The Sencha Touch Cookbook really is your one stop resource for cross platform HTML5 application development. It covers the basics such as setting up an iOS and Android development environment right through to much more complex development issues such as touch gestures, animation, rich media and geo location. Every recipe is practically focused. Maximum action. Minimum theory.
Table of Contents (17 chapters)
Sencha Touch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Detecting the device


Different devices offer different capabilities and hence for an application developer, it becomes important to identify the exact device, so that it can respond to the events in the most appropriate way. This recipe describes how we can detect the device on which the application is being run.

How to do it...

Carry out the following steps:

  1. Create and open a new file ch01_02.js in the ch01 folder and paste the following code into it:

    Ext.setup({
      onReady: function() {
        if (Ext.is.Android)
          Ext.Msg.alert("INFO", "Welcome Android user!");
          
        if (Ext.is.Blackberry)
          Ext.Msg.alert("INFO", "Welcome Blackberry user!");
          
        if (Ext.is.iPad)
          Ext.Msg.alert("INFO", "Welcome iPad user!");
      }
    });
  2. Remove the following line from index.html:

    <script type="text/javascript" charset="utf-8" src="ch01/ch01_01.js"></script>
  3. Include the following line in index.html:

    <script type="text/javascript" charset="utf-8" src="ch01/ch01_02.js"></script>
  4. Deploy and run the application. Based on the device on which the application is being run, you will see a corresponding message.

How it works...

The Ext.is class is instrumental in detecting the target device on which your application is being run. It uses the JavaScript's navigator object to detect the browser details, including the platform/device. For example, if the platform property in the navigator object has iPhone in it, then the target platform is iPhone, whereas if the userAgent property in the navigator object has Android, then the platform is Android.

See also

  • The recipe named Setting up the browser-based development environment in this chapter

  • The recipe named Setting up the production environment in this chapter