- Sencha Touch Cookbook
- Ajit Kumar
- 231字
- 2021-08-20 15:56:06
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:
- Create and open a new file
ch01_02.js
in thech01
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!"); } });
- Remove the following line from
index.html
:<script type="text/javascript" charset="utf-8" src="ch01/ch01_01.js"></script>
- Include the following line in
index.html
:<script type="text/javascript" charset="utf-8" src="ch01/ch01_02.js"></script>
- 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
推薦閱讀
- TypeScript Blueprints
- Microsoft Application Virtualization Cookbook
- Visual Basic程序設計習題解答與上機指導
- 精通Linux(第2版)
- Python算法指南:程序員經典算法分析與實現
- Python算法詳解
- SQL Server數據庫管理與開發兵書
- C和C++游戲趣味編程
- Java零基礎實戰
- MySQL 8從零開始學(視頻教學版)
- C# 7.0本質論
- Puppet 5 Beginner's Guide(Third Edition)
- Extending Docker
- Unity虛擬現實開發圣典
- MonoTouch應用開發實踐指南:使用C#和.NET開發iOS應用