mobileesp_converted 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1026 @@
1
+ /* *******************************************
2
+ // Copyright 2010-2012, Anthony Hand
3
+ //
4
+ // File version date: January 21, 2012
5
+ // Update:
6
+ // - Moved Windows Phone 7 to the iPhone Tier. WP7.5's IE 9-based browser is good enough now.
7
+ // - Added a new variable for 2 versions of the new BlackBerry Bold Touch (9900 and 9930): deviceBBBoldTouch.
8
+ // - Updated DetectBlackBerryTouch() to support the 2 versions of the new BlackBerry Bold Touch (9900 and 9930).
9
+ // - Updated DetectKindle() to focus on eInk devices only. The Kindle Fire should be detected as a regular Android device.
10
+ //
11
+ // File version date: August 22, 2011
12
+ // Update:
13
+ // - Updated DetectAndroidTablet() to fix a bug I introduced in the last fix!
14
+ //
15
+ // File version date: August 16, 2011
16
+ // Update:
17
+ // - Updated DetectAndroidTablet() to exclude Opera Mini, which was falsely reporting as running on a tablet device when on a phone.
18
+ //
19
+ // File version date: August 7, 2011
20
+ // Update:
21
+ // - The Opera for Android browser doesn't follow Google's recommended useragent string guidelines, so some fixes were needed.
22
+ // - Updated DetectAndroidPhone() and DetectAndroidTablet() to properly detect devices running Opera Mobile.
23
+ // - Created 2 new methods: DetectOperaAndroidPhone() and DetectOperaAndroidTablet().
24
+ // - Updated DetectTierIphone(). Removed the call to DetectMaemoTablet(), an obsolete mobile OS.
25
+ //
26
+ //
27
+ // LICENSE INFORMATION
28
+ // Licensed under the Apache License, Version 2.0 (the "License");
29
+ // you may not use this file except in compliance with the License.
30
+ // You may obtain a copy of the License at
31
+ // http://www.apache.org/licenses/LICENSE-2.0
32
+ // Unless required by applicable law or agreed to in writing,
33
+ // software distributed under the License is distributed on an
34
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
35
+ // either express or implied. See the License for the specific
36
+ // language governing permissions and limitations under the License.
37
+ //
38
+ //
39
+ // ABOUT THIS PROJECT
40
+ // Project Owner: Anthony Hand
41
+ // Email: anthony.hand@gmail.com
42
+ // Web Site: http://www.mobileesp.com
43
+ // Source Files: http://code.google.com/p/mobileesp/
44
+ //
45
+ // Versions of this code are available for:
46
+ // PHP, JavaScript, Java, ASP.NET (C#), and Ruby
47
+ //
48
+ // *******************************************
49
+ */
50
+ package com.handinteractive.mobile;
51
+
52
+ /**
53
+ * The DetectSmartPhone class encapsulates information about
54
+ * a browser's connection to your web site.
55
+ * You can use it to find out whether the browser asking for
56
+ * your site's content is probably running on a mobile device.
57
+ * The methods were written so you can be as granular as you want.
58
+ * For example, enquiring whether it's as specific as an iPod Touch or
59
+ * as general as a smartphone class device.
60
+ * The object's methods return true, or false.
61
+ */
62
+ public class UAgentInfo {
63
+ // User-Agent and Accept HTTP request headers
64
+
65
+ private String userAgent = "";
66
+ private String httpAccept = "";
67
+
68
+ // Let's store values for quickly accessing the same info multiple times.
69
+ public boolean isIphone = false;
70
+ public boolean isAndroidPhone = false;
71
+ public boolean isTierTablet = false;
72
+ public boolean isTierIphone = false;
73
+ public boolean isTierRichCss = false;
74
+ public boolean isTierGenericMobile = false;
75
+
76
+ // Initialize some initial smartphone string variables.
77
+ public static final String engineWebKit = "webkit";
78
+
79
+ public static final String deviceIphone = "iphone";
80
+ public static final String deviceIpod = "ipod";
81
+ public static final String deviceIpad = "ipad";
82
+ public static final String deviceMacPpc = "macintosh"; //Used for disambiguation
83
+
84
+ public static final String deviceAndroid = "android";
85
+ public static final String deviceGoogleTV = "googletv";
86
+ public static final String deviceXoom = "xoom"; //Motorola Xoom
87
+ public static final String deviceHtcFlyer = "htc_flyer"; //HTC Flyer
88
+
89
+ public static final String deviceSymbian = "symbian";
90
+ public static final String deviceS60 = "series60";
91
+ public static final String deviceS70 = "series70";
92
+ public static final String deviceS80 = "series80";
93
+ public static final String deviceS90 = "series90";
94
+
95
+ public static final String deviceWinPhone7 = "windows phone os 7";
96
+ public static final String deviceWinMob = "windows ce";
97
+ public static final String deviceWindows = "windows";
98
+ public static final String deviceIeMob = "iemobile";
99
+ public static final String devicePpc = "ppc"; //Stands for PocketPC
100
+ public static final String enginePie = "wm5 pie"; //An old Windows Mobile
101
+
102
+ public static final String deviceBB = "blackberry";
103
+ public static final String vndRIM = "vnd.rim"; //Detectable when BB devices emulate IE or Firefox
104
+ public static final String deviceBBStorm = "blackberry95"; //Storm 1 and 2
105
+ public static final String deviceBBBold = "blackberry97"; //Bold 97x0 (non-touch)
106
+ public static final String deviceBBBoldTouch = "blackberry 99"; //Bold 99x0 (touchscreen)
107
+ public static final String deviceBBTour = "blackberry96"; //Tour
108
+ public static final String deviceBBCurve = "blackberry89"; //Curve 2
109
+ public static final String deviceBBTorch = "blackberry 98"; //Torch
110
+ public static final String deviceBBPlaybook = "playbook"; //PlayBook tablet
111
+
112
+ public static final String devicePalm = "palm";
113
+ public static final String deviceWebOS = "webos"; //For Palm's line of WebOS devices
114
+ public static final String deviceWebOShp = "hpwos"; //For HP's line of WebOS devices
115
+
116
+ public static final String engineBlazer = "blazer"; //Old Palm
117
+ public static final String engineXiino = "xiino"; //Another old Palm
118
+
119
+ public static final String deviceKindle = "kindle"; //Amazon Kindle, eInk one.
120
+
121
+ public static final String deviceNuvifone = "nuvifone"; //Garmin Nuvifone
122
+
123
+ //Initialize variables for mobile-specific content.
124
+ public static final String vndwap = "vnd.wap";
125
+ public static final String wml = "wml";
126
+
127
+ //Initialize variables for other random devices and mobile browsers.
128
+ public static final String deviceTablet = "tablet"; //Generic term for slate and tablet devices
129
+ public static final String deviceBrew = "brew";
130
+ public static final String deviceDanger = "danger";
131
+ public static final String deviceHiptop = "hiptop";
132
+ public static final String devicePlaystation = "playstation";
133
+ public static final String deviceNintendoDs = "nitro";
134
+ public static final String deviceNintendo = "nintendo";
135
+ public static final String deviceWii = "wii";
136
+ public static final String deviceXbox = "xbox";
137
+ public static final String deviceArchos = "archos";
138
+
139
+ public static final String engineOpera = "opera"; //Popular browser
140
+ public static final String engineNetfront = "netfront"; //Common embedded OS browser
141
+ public static final String engineUpBrowser = "up.browser"; //common on some phones
142
+ public static final String engineOpenWeb = "openweb"; //Transcoding by OpenWave server
143
+ public static final String deviceMidp = "midp"; //a mobile Java technology
144
+ public static final String uplink = "up.link";
145
+ public static final String engineTelecaQ = "teleca q"; //a modern feature phone browser
146
+ public static final String devicePda = "pda"; //some devices report themselves as PDAs
147
+ public static final String mini = "mini"; //Some mobile browsers put "mini" in their names.
148
+ public static final String mobile = "mobile"; //Some mobile browsers put "mobile" in their user agent strings.
149
+ public static final String mobi = "mobi"; //Some mobile browsers put "mobi" in their user agent strings.
150
+
151
+ //Use Maemo, Tablet, and Linux to test for Nokia"s Internet Tablets.
152
+ public static final String maemo = "maemo";
153
+ public static final String linux = "linux";
154
+ public static final String qtembedded = "qt embedded"; //for Sony Mylo
155
+ public static final String mylocom2 = "com2"; //for Sony Mylo also
156
+
157
+ //In some UserAgents, the only clue is the manufacturer.
158
+ public static final String manuSonyEricsson = "sonyericsson";
159
+ public static final String manuericsson = "ericsson";
160
+ public static final String manuSamsung1 = "sec-sgh";
161
+ public static final String manuSony = "sony";
162
+ public static final String manuHtc = "htc"; //Popular Android and WinMo manufacturer
163
+
164
+ //In some UserAgents, the only clue is the operator.
165
+ public static final String svcDocomo = "docomo";
166
+ public static final String svcKddi = "kddi";
167
+ public static final String svcVodafone = "vodafone";
168
+
169
+ //Disambiguation strings.
170
+ public static final String disUpdate = "update"; //pda vs. update
171
+
172
+
173
+ /**
174
+ * Initialize the userAgent and httpAccept variables
175
+ *
176
+ * @param userAgent the User-Agent header
177
+ * @param httpAccept the Accept header
178
+ */
179
+ public UAgentInfo(String userAgent, String httpAccept) {
180
+ if (userAgent != null) {
181
+ this.userAgent = userAgent.toLowerCase();
182
+ }
183
+ if (httpAccept != null) {
184
+ this.httpAccept = httpAccept.toLowerCase();
185
+ }
186
+
187
+ //Intialize key stored values.
188
+ initDeviceScan();
189
+ }
190
+
191
+ /**
192
+ * Return the lower case HTTP_USER_AGENT
193
+ * @return userAgent
194
+ */
195
+ public String getUserAgent() {
196
+ return userAgent;
197
+ }
198
+
199
+ /**
200
+ * Return the lower case HTTP_ACCEPT
201
+ * @return httpAccept
202
+ */
203
+ public String getHttpAccept() {
204
+ return httpAccept;
205
+ }
206
+
207
+ /**
208
+ * Return whether the device is an Iphone or iPod Touch
209
+ * @return isIphone
210
+ */
211
+ public boolean getIsIphone() {
212
+ return isIphone;
213
+ }
214
+
215
+ /**
216
+ * Return whether the device is in the Tablet Tier.
217
+ * @return isTierTablet
218
+ */
219
+ public boolean getIsTierTablet() {
220
+ return isTierTablet;
221
+ }
222
+
223
+ /**
224
+ * Return whether the device is in the Iphone Tier.
225
+ * @return isTierIphone
226
+ */
227
+ public boolean getIsTierIphone() {
228
+ return isTierIphone;
229
+ }
230
+
231
+ /**
232
+ * Return whether the device is in the 'Rich CSS' tier of mobile devices.
233
+ * @return isTierRichCss
234
+ */
235
+ public boolean getIsTierRichCss() {
236
+ return isTierRichCss;
237
+ }
238
+
239
+ /**
240
+ * Return whether the device is a generic, less-capable mobile device.
241
+ * @return isTierGenericMobile
242
+ */
243
+ public boolean getIsTierGenericMobile() {
244
+ return isTierGenericMobile;
245
+ }
246
+
247
+ /**
248
+ * Initialize Key Stored Values.
249
+ */
250
+ public void initDeviceScan() {
251
+ this.isIphone = detectIphoneOrIpod();
252
+ this.isAndroidPhone = detectAndroidPhone();
253
+ this.isTierTablet = detectTierTablet();
254
+ this.isTierIphone = detectTierIphone();
255
+ this.isTierRichCss = detectTierRichCss();
256
+ this.isTierGenericMobile = detectTierOtherPhones();
257
+ }
258
+
259
+ /**
260
+ * Detects if the current device is an iPhone.
261
+ * @return detection of an iPhone
262
+ */
263
+ public boolean detectIphone() {
264
+ // The iPad and iPod touch say they're an iPhone! So let's disambiguate.
265
+ if (userAgent.indexOf(deviceIphone) != -1 &&
266
+ !detectIpad() &&
267
+ !detectIpod()) {
268
+ return true;
269
+ }
270
+ return false;
271
+ }
272
+
273
+ /**
274
+ * Detects if the current device is an iPod Touch.
275
+ * @return detection of an iPod Touch
276
+ */
277
+ public boolean detectIpod() {
278
+ if (userAgent.indexOf(deviceIpod) != -1) {
279
+ return true;
280
+ }
281
+ return false;
282
+ }
283
+
284
+ /**
285
+ * Detects if the current device is an iPad tablet.
286
+ * @return detection of an iPad
287
+ */
288
+ public boolean detectIpad() {
289
+ if (userAgent.indexOf(deviceIpad) != -1
290
+ && detectWebkit()) {
291
+ return true;
292
+ }
293
+ return false;
294
+ }
295
+
296
+ /**
297
+ * Detects if the current device is an iPhone or iPod Touch.
298
+ * @return detection of an iPhone or iPod Touch
299
+ */
300
+ public boolean detectIphoneOrIpod() {
301
+ //We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay.
302
+ if (userAgent.indexOf(deviceIphone) != -1
303
+ || userAgent.indexOf(deviceIpod) != -1) {
304
+ return true;
305
+ }
306
+ return false;
307
+ }
308
+
309
+ /**
310
+ * Detects *any* iOS device: iPhone, iPod Touch, iPad.
311
+ * @return detection of an Apple iOS device
312
+ */
313
+ public boolean detectIos() {
314
+ if (detectIphoneOrIpod() || detectIpad()) {
315
+ return true;
316
+ }
317
+ return false;
318
+ }
319
+
320
+
321
+ /**
322
+ * Detects *any* Android OS-based device: phone, tablet, and multi-media player.
323
+ * Also detects Google TV.
324
+ * @return detection of an Android device
325
+ */
326
+ public boolean detectAndroid() {
327
+ if ((userAgent.indexOf(deviceAndroid) != -1) ||
328
+ detectGoogleTV())
329
+ return true;
330
+ //Special check for the HTC Flyer 7" tablet. It should report here.
331
+ if (userAgent.indexOf(deviceHtcFlyer) != -1)
332
+ return true;
333
+ return false;
334
+ }
335
+
336
+ /**
337
+ * Detects if the current device is a (small-ish) Android OS-based device
338
+ * used for calling and/or multi-media (like a Samsung Galaxy Player).
339
+ * Google says these devices will have 'Android' AND 'mobile' in user agent.
340
+ * Ignores tablets (Honeycomb and later).
341
+ * @return detection of an Android phone
342
+ */
343
+ public boolean detectAndroidPhone() {
344
+ if (detectAndroid() && (userAgent.indexOf(mobile) != -1))
345
+ return true;
346
+ //Special check for Android phones with Opera Mobile. They should report here.
347
+ if (detectOperaAndroidPhone())
348
+ return true;
349
+ //Special check for the HTC Flyer 7" tablet. It should report here.
350
+ if (userAgent.indexOf(deviceHtcFlyer) != -1)
351
+ return true;
352
+ return false;
353
+ }
354
+
355
+ /**
356
+ * Detects if the current device is a (self-reported) Android tablet.
357
+ * Google says these devices will have 'Android' and NOT 'mobile' in their user agent.
358
+ * @return detection of an Android tablet
359
+ */
360
+ public boolean detectAndroidTablet() {
361
+ //First, let's make sure we're on an Android device.
362
+ if (!detectAndroid())
363
+ return false;
364
+
365
+ //Special check for Opera Android Phones. They should NOT report here.
366
+ if (detectOperaMobile())
367
+ return false;
368
+ //Special check for the HTC Flyer 7" tablet. It should NOT report here.
369
+ if (userAgent.indexOf(deviceHtcFlyer) != -1)
370
+ return false;
371
+
372
+ //Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet.
373
+ if ((userAgent.indexOf(mobile) > -1))
374
+ return false;
375
+ else
376
+ return true;
377
+ }
378
+
379
+ /**
380
+ * Detects if the current device is an Android OS-based device and
381
+ * the browser is based on WebKit.
382
+ * @return detection of an Android WebKit browser
383
+ */
384
+ public boolean detectAndroidWebKit() {
385
+ if (detectAndroid() && detectWebkit()) {
386
+ return true;
387
+ }
388
+ return false;
389
+ }
390
+
391
+ /**
392
+ * Detects if the current device is a GoogleTV.
393
+ * @return detection of GoogleTV
394
+ */
395
+ public boolean detectGoogleTV() {
396
+ if (userAgent.indexOf(deviceGoogleTV) != -1) {
397
+ return true;
398
+ }
399
+ return false;
400
+ }
401
+
402
+ /**
403
+ * Detects if the current browser is based on WebKit.
404
+ * @return detection of a WebKit browser
405
+ */
406
+ public boolean detectWebkit() {
407
+ if (userAgent.indexOf(engineWebKit) != -1) {
408
+ return true;
409
+ }
410
+ return false;
411
+ }
412
+
413
+ /**
414
+ * Detects if the current browser is the Symbian S60 Open Source Browser.
415
+ * @return detection of Symbian S60 Browser
416
+ */
417
+ public boolean detectS60OssBrowser() {
418
+ //First, test for WebKit, then make sure it's either Symbian or S60.
419
+ if (detectWebkit()
420
+ && (userAgent.indexOf(deviceSymbian) != -1
421
+ || userAgent.indexOf(deviceS60) != -1)) {
422
+ return true;
423
+ }
424
+ return false;
425
+ }
426
+
427
+ /**
428
+ *
429
+ * Detects if the current device is any Symbian OS-based device,
430
+ * including older S60, Series 70, Series 80, Series 90, and UIQ,
431
+ * or other browsers running on these devices.
432
+ * @return detection of SymbianOS
433
+ */
434
+ public boolean detectSymbianOS() {
435
+ if (userAgent.indexOf(deviceSymbian) != -1
436
+ || userAgent.indexOf(deviceS60) != -1
437
+ || userAgent.indexOf(deviceS70) != -1
438
+ || userAgent.indexOf(deviceS80) != -1
439
+ || userAgent.indexOf(deviceS90) != -1) {
440
+ return true;
441
+ }
442
+ return false;
443
+ }
444
+
445
+ /**
446
+ * Detects if the current browser is a
447
+ * Windows Phone 7 device.
448
+ * @return detection of Windows Phone 7
449
+ */
450
+ public boolean detectWindowsPhone7() {
451
+ if (userAgent.indexOf(deviceWinPhone7) != -1) {
452
+ return true;
453
+ }
454
+ return false;
455
+ }
456
+
457
+ /**
458
+ * Detects if the current browser is a Windows Mobile device.
459
+ * Excludes Windows Phone 7 devices.
460
+ * Focuses on Windows Mobile 6.xx and earlier.
461
+ * @return detection of Windows Mobile
462
+ */
463
+ public boolean detectWindowsMobile() {
464
+ //Exclude new Windows Phone 7.
465
+ if (detectWindowsPhone7()) {
466
+ return false;
467
+ }
468
+ //Most devices use 'Windows CE', but some report 'iemobile'
469
+ // and some older ones report as 'PIE' for Pocket IE.
470
+ // We also look for instances of HTC and Windows for many of their WinMo devices.
471
+ if (userAgent.indexOf(deviceWinMob) != -1
472
+ || userAgent.indexOf(deviceWinMob) != -1
473
+ || userAgent.indexOf(deviceIeMob) != -1
474
+ || userAgent.indexOf(enginePie) != -1
475
+ || (userAgent.indexOf(manuHtc) != -1 && userAgent.indexOf(deviceWindows) != -1)
476
+ || (detectWapWml() && userAgent.indexOf(deviceWindows) != -1)) {
477
+ return true;
478
+ }
479
+
480
+ //Test for Windows Mobile PPC but not old Macintosh PowerPC.
481
+ if (userAgent.indexOf(devicePpc) != -1 &&
482
+ !(userAgent.indexOf(deviceMacPpc) != -1))
483
+ return true;
484
+
485
+ return false;
486
+ }
487
+
488
+ /**
489
+ * Detects if the current browser is any BlackBerry.
490
+ * Includes the PlayBook.
491
+ * @return detection of Blackberry
492
+ */
493
+ public boolean detectBlackBerry() {
494
+ if (userAgent.indexOf(deviceBB) != -1 ||
495
+ httpAccept.indexOf(vndRIM) != -1) {
496
+ return true;
497
+ }
498
+ return false;
499
+ }
500
+
501
+ /**
502
+ * Detects if the current browser is on a BlackBerry tablet device.
503
+ * Example: PlayBook
504
+ * @return detection of a Blackberry Tablet
505
+ */
506
+ public boolean detectBlackBerryTablet() {
507
+ if (userAgent.indexOf(deviceBBPlaybook) != -1) {
508
+ return true;
509
+ }
510
+ return false;
511
+ }
512
+
513
+ /**
514
+ * Detects if the current browser is a BlackBerry device AND uses a
515
+ * WebKit-based browser. These are signatures for the new BlackBerry OS 6.
516
+ * Examples: Torch. Includes the Playbook.
517
+ * @return detection of a Blackberry device with WebKit browser
518
+ */
519
+ public boolean detectBlackBerryWebKit() {
520
+ if (detectBlackBerry() &&
521
+ userAgent.indexOf(engineWebKit) != -1) {
522
+ return true;
523
+ }
524
+ return false;
525
+ }
526
+
527
+ /**
528
+ * Detects if the current browser is a BlackBerry Touch
529
+ * device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook.
530
+ * @return detection of a Blackberry touchscreen device
531
+ */
532
+ public boolean detectBlackBerryTouch() {
533
+ if (detectBlackBerry() &&
534
+ (userAgent.indexOf(deviceBBStorm) != -1 ||
535
+ userAgent.indexOf(deviceBBTorch) != -1 ||
536
+ userAgent.indexOf(deviceBBBoldTouch) != -1)) {
537
+ return true;
538
+ }
539
+ return false;
540
+ }
541
+
542
+ /**
543
+ * Detects if the current browser is a BlackBerry device AND
544
+ * has a more capable recent browser. Excludes the Playbook.
545
+ * Examples, Storm, Bold, Tour, Curve2
546
+ * Excludes the new BlackBerry OS 6 and 7 browser!!
547
+ * @return detection of a Blackberry device with a better browser
548
+ */
549
+ public boolean detectBlackBerryHigh() {
550
+ //Disambiguate for BlackBerry OS 6 or 7 (WebKit) browser
551
+ if (detectBlackBerryWebKit())
552
+ return false;
553
+ if (detectBlackBerry()) {
554
+ if (detectBlackBerryTouch()
555
+ || userAgent.indexOf(deviceBBBold) != -1
556
+ || userAgent.indexOf(deviceBBTour) != -1
557
+ || userAgent.indexOf(deviceBBCurve) != -1) {
558
+ return true;
559
+ } else {
560
+ return false;
561
+ }
562
+ } else {
563
+ return false;
564
+ }
565
+ }
566
+
567
+ /**
568
+ * Detects if the current browser is a BlackBerry device AND
569
+ * has an older, less capable browser.
570
+ * Examples: Pearl, 8800, Curve1
571
+ * @return detection of a Blackberry device with a poorer browser
572
+ */
573
+ public boolean detectBlackBerryLow() {
574
+ if (detectBlackBerry()) {
575
+ //Assume that if it's not in the High tier, then it's Low
576
+ if (detectBlackBerryHigh()
577
+ || detectBlackBerryWebKit()) {
578
+ return false;
579
+ } else {
580
+ return true;
581
+ }
582
+ } else {
583
+ return false;
584
+ }
585
+ }
586
+
587
+ /**
588
+ * Detects if the current browser is on a PalmOS device.
589
+ * @return detection of a PalmOS device
590
+ */
591
+ public boolean detectPalmOS() {
592
+ //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino.
593
+ if (userAgent.indexOf(devicePalm) != -1
594
+ || userAgent.indexOf(engineBlazer) != -1
595
+ || userAgent.indexOf(engineXiino) != -1) {
596
+ //Make sure it's not WebOS first
597
+ if (detectPalmWebOS()) {
598
+ return false;
599
+ } else {
600
+ return true;
601
+ }
602
+ }
603
+ return false;
604
+ }
605
+
606
+ /**
607
+ * Detects if the current browser is on a Palm device
608
+ * running the new WebOS.
609
+ * @return detection of a Palm WebOS device
610
+ */
611
+ public boolean detectPalmWebOS() {
612
+ if (userAgent.indexOf(deviceWebOS) != -1) {
613
+ return true;
614
+ }
615
+ return false;
616
+ }
617
+
618
+ /**
619
+ * Detects if the current browser is on an HP tablet running WebOS.
620
+ * @return detection of an HP WebOS tablet
621
+ */
622
+ public boolean detectWebOSTablet() {
623
+ if (userAgent.indexOf(deviceWebOShp) != -1 &&
624
+ userAgent.indexOf(deviceTablet) != -1) {
625
+ return true;
626
+ }
627
+ return false;
628
+ }
629
+
630
+ /**
631
+ * Detects if the current browser is a
632
+ * Garmin Nuvifone.
633
+ * @return detection of a Garmin Nuvifone
634
+ */
635
+ public boolean detectGarminNuvifone() {
636
+ if (userAgent.indexOf(deviceNuvifone) != -1) {
637
+ return true;
638
+ }
639
+ return false;
640
+ }
641
+
642
+ /**
643
+ * Check to see whether the device is any device
644
+ * in the 'smartphone' category.
645
+ * @return detection of a general smartphone device
646
+ */
647
+ public boolean detectSmartphone() {
648
+ return (isIphone
649
+ || isAndroidPhone
650
+ || isTierIphone
651
+ || detectS60OssBrowser()
652
+ || detectSymbianOS()
653
+ || detectWindowsMobile()
654
+ || detectWindowsPhone7()
655
+ || detectBlackBerry()
656
+ || detectPalmWebOS()
657
+ || detectPalmOS()
658
+ || detectGarminNuvifone());
659
+ }
660
+
661
+ /**
662
+ * Detects whether the device is a Brew-powered device.
663
+ * @return detection of a Brew device
664
+ */
665
+ public boolean detectBrewDevice() {
666
+ if (userAgent.indexOf(deviceBrew) != -1) {
667
+ return true;
668
+ }
669
+ return false;
670
+ }
671
+
672
+ /**
673
+ * Detects the Danger Hiptop device.
674
+ * @return detection of a Danger Hiptop
675
+ */
676
+ public boolean detectDangerHiptop() {
677
+ if (userAgent.indexOf(deviceDanger) != -1
678
+ || userAgent.indexOf(deviceHiptop) != -1) {
679
+ return true;
680
+ }
681
+ return false;
682
+ }
683
+
684
+ /**
685
+ * Detects Opera Mobile or Opera Mini.
686
+ * @return detection of an Opera browser for a mobile device
687
+ */
688
+ public boolean detectOperaMobile() {
689
+ if (userAgent.indexOf(engineOpera) != -1
690
+ && (userAgent.indexOf(mini) != -1
691
+ || userAgent.indexOf(mobi) != -1)) {
692
+ return true;
693
+ }
694
+ return false;
695
+ }
696
+
697
+ /**
698
+ * Detects Opera Mobile on an Android phone.
699
+ * @return detection of an Opera browser on an Android phone
700
+ */
701
+ public boolean detectOperaAndroidPhone() {
702
+ if (userAgent.indexOf(engineOpera) != -1
703
+ && (userAgent.indexOf(deviceAndroid) != -1
704
+ && userAgent.indexOf(mobi) != -1)) {
705
+ return true;
706
+ }
707
+ return false;
708
+ }
709
+
710
+ /**
711
+ * Detects Opera Mobile on an Android tablet.
712
+ * @return detection of an Opera browser on an Android tablet
713
+ */
714
+ public boolean detectOperaAndroidTablet() {
715
+ if (userAgent.indexOf(engineOpera) != -1
716
+ && (userAgent.indexOf(deviceAndroid) != -1
717
+ && userAgent.indexOf(deviceTablet) != -1)) {
718
+ return true;
719
+ }
720
+ return false;
721
+ }
722
+
723
+ /**
724
+ * Detects whether the device supports WAP or WML.
725
+ * @return detection of a WAP- or WML-capable device
726
+ */
727
+ public boolean detectWapWml() {
728
+ if (httpAccept.indexOf(vndwap) != -1
729
+ || httpAccept.indexOf(wml) != -1) {
730
+ return true;
731
+ }
732
+ return false;
733
+ }
734
+
735
+ /**
736
+ * Detects if the current device is an Amazon Kindle (eInk devices only).
737
+ * Note: For the Kindle Fire, use the normal Android methods.
738
+ * @return detection of a Kindle
739
+ */
740
+ public boolean detectKindle() {
741
+ if (userAgent.indexOf(deviceKindle)!= -1 &&
742
+ !detectAndroid()) {
743
+ return true;
744
+ }
745
+ return false;
746
+ }
747
+
748
+ /**
749
+ * Detects if the current device is a mobile device.
750
+ * This method catches most of the popular modern devices.
751
+ * Excludes Apple iPads and other modern tablets.
752
+ * @return detection of any mobile device using the quicker method
753
+ */
754
+ public boolean detectMobileQuick() {
755
+ //Let's exclude tablets
756
+ if (isTierTablet) {
757
+ return false;
758
+ }
759
+ //Most mobile browsing is done on smartphones
760
+ if (detectSmartphone()) {
761
+ return true;
762
+ }
763
+
764
+ if (detectWapWml()
765
+ || detectBrewDevice()
766
+ || detectOperaMobile()) {
767
+ return true;
768
+ }
769
+
770
+ if ((userAgent.indexOf(engineNetfront) != -1)
771
+ || (userAgent.indexOf(engineUpBrowser) != -1)
772
+ || (userAgent.indexOf(engineOpenWeb) != -1)) {
773
+ return true;
774
+ }
775
+
776
+ if (detectDangerHiptop()
777
+ || detectMidpCapable()
778
+ || detectMaemoTablet()
779
+ || detectArchos()) {
780
+ return true;
781
+ }
782
+
783
+ if ((userAgent.indexOf(devicePda) != -1) &&
784
+ (userAgent.indexOf(disUpdate) < 0)) //no index found
785
+ {
786
+ return true;
787
+ }
788
+ if (userAgent.indexOf(mobile) != -1) {
789
+ return true;
790
+ }
791
+
792
+ return false;
793
+ }
794
+
795
+ /**
796
+ * Detects if the current device is a Sony Playstation.
797
+ * @return detection of Sony Playstation
798
+ */
799
+ public boolean detectSonyPlaystation() {
800
+ if (userAgent.indexOf(devicePlaystation) != -1) {
801
+ return true;
802
+ }
803
+ return false;
804
+ }
805
+
806
+ /**
807
+ * Detects if the current device is a Nintendo game device.
808
+ * @return detection of Nintendo
809
+ */
810
+ public boolean detectNintendo() {
811
+ if (userAgent.indexOf(deviceNintendo) != -1
812
+ || userAgent.indexOf(deviceWii) != -1
813
+ || userAgent.indexOf(deviceNintendoDs) != -1) {
814
+ return true;
815
+ }
816
+ return false;
817
+ }
818
+
819
+ /**
820
+ * Detects if the current device is a Microsoft Xbox.
821
+ * @return detection of Xbox
822
+ */
823
+ public boolean detectXbox() {
824
+ if (userAgent.indexOf(deviceXbox) != -1) {
825
+ return true;
826
+ }
827
+ return false;
828
+ }
829
+
830
+ /**
831
+ * Detects if the current device is an Internet-capable game console.
832
+ * @return detection of any Game Console
833
+ */
834
+ public boolean detectGameConsole() {
835
+ if (detectSonyPlaystation()
836
+ || detectNintendo()
837
+ || detectXbox()) {
838
+ return true;
839
+ }
840
+ return false;
841
+ }
842
+
843
+ /**
844
+ * Detects if the current device supports MIDP, a mobile Java technology.
845
+ * @return detection of a MIDP mobile Java-capable device
846
+ */
847
+ public boolean detectMidpCapable() {
848
+ if (userAgent.indexOf(deviceMidp) != -1
849
+ || httpAccept.indexOf(deviceMidp) != -1) {
850
+ return true;
851
+ }
852
+ return false;
853
+ }
854
+
855
+ /**
856
+ * Detects if the current device is on one of the Maemo-based Nokia Internet Tablets.
857
+ * @return detection of a Maemo OS tablet
858
+ */
859
+ public boolean detectMaemoTablet() {
860
+ if (userAgent.indexOf(maemo) != -1) {
861
+ return true;
862
+ } else if (userAgent.indexOf(linux) != -1
863
+ && userAgent.indexOf(deviceTablet) != -1
864
+ && !detectWebOSTablet()
865
+ && !detectAndroid()) {
866
+ return true;
867
+ }
868
+ return false;
869
+ }
870
+
871
+ /**
872
+ * Detects if the current device is an Archos media player/Internet tablet.
873
+ * @return detection of an Archos media player
874
+ */
875
+ public boolean detectArchos() {
876
+ if (userAgent.indexOf(deviceArchos) != -1) {
877
+ return true;
878
+ }
879
+ return false;
880
+ }
881
+
882
+ /**
883
+ * Detects if the current browser is a Sony Mylo device.
884
+ * @return detection of a Sony Mylo device
885
+ */
886
+ public boolean detectSonyMylo() {
887
+ if (userAgent.indexOf(manuSony) != -1
888
+ && (userAgent.indexOf(qtembedded) != -1
889
+ || userAgent.indexOf(mylocom2) != -1)) {
890
+ return true;
891
+ }
892
+ return false;
893
+ }
894
+
895
+ /**
896
+ * The longer and more thorough way to detect for a mobile device.
897
+ * Will probably detect most feature phones,
898
+ * smartphone-class devices, Internet Tablets,
899
+ * Internet-enabled game consoles, etc.
900
+ * This ought to catch a lot of the more obscure and older devices, also --
901
+ * but no promises on thoroughness!
902
+ * @return detection of any mobile device using the more thorough method
903
+ */
904
+ public boolean detectMobileLong() {
905
+ if (detectMobileQuick()
906
+ || detectGameConsole()
907
+ || detectSonyMylo()) {
908
+ return true;
909
+ }
910
+
911
+ //detect older phones from certain manufacturers and operators.
912
+ if (userAgent.indexOf(uplink) != -1) {
913
+ return true;
914
+ }
915
+ if (userAgent.indexOf(manuSonyEricsson) != -1) {
916
+ return true;
917
+ }
918
+ if (userAgent.indexOf(manuericsson) != -1) {
919
+ return true;
920
+ }
921
+ if (userAgent.indexOf(manuSamsung1) != -1) {
922
+ return true;
923
+ }
924
+
925
+ if (userAgent.indexOf(svcDocomo) != -1) {
926
+ return true;
927
+ }
928
+ if (userAgent.indexOf(svcKddi) != -1) {
929
+ return true;
930
+ }
931
+ if (userAgent.indexOf(svcVodafone) != -1) {
932
+ return true;
933
+ }
934
+
935
+ return false;
936
+ }
937
+
938
+ //*****************************
939
+ // For Mobile Web Site Design
940
+ //*****************************
941
+
942
+ /**
943
+ * The quick way to detect for a tier of devices.
944
+ * This method detects for the new generation of
945
+ * HTML 5 capable, larger screen tablets.
946
+ * Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc.
947
+ * @return detection of any device in the Tablet Tier
948
+ */
949
+ public boolean detectTierTablet() {
950
+ if (detectIpad()
951
+ || detectAndroidTablet()
952
+ || detectBlackBerryTablet()
953
+ || detectWebOSTablet()) {
954
+ return true;
955
+ }
956
+ return false;
957
+ }
958
+
959
+ /**
960
+ * The quick way to detect for a tier of devices.
961
+ * This method detects for devices which can
962
+ * display iPhone-optimized web content.
963
+ * Includes iPhone, iPod Touch, Android, Windows Phone 7, Palm WebOS, etc.
964
+ * @return detection of any device in the iPhone/Android/WP7/WebOS Tier
965
+ */
966
+ public boolean detectTierIphone() {
967
+ if (isIphone
968
+ || isAndroidPhone
969
+ || (detectBlackBerryWebKit()
970
+ && detectBlackBerryTouch())
971
+ || detectWindowsPhone7()
972
+ || detectPalmWebOS()
973
+ || detectGarminNuvifone()) {
974
+ return true;
975
+ }
976
+ return false;
977
+ }
978
+
979
+ /**
980
+ * The quick way to detect for a tier of devices.
981
+ * This method detects for devices which are likely to be capable
982
+ * of viewing CSS content optimized for the iPhone,
983
+ * but may not necessarily support JavaScript.
984
+ * Excludes all iPhone Tier devices.
985
+ * @return detection of any device in the 'Rich CSS' Tier
986
+ */
987
+ public boolean detectTierRichCss() {
988
+ boolean result = false;
989
+ //The following devices are explicitly ok.
990
+ //Note: 'High' BlackBerry devices ONLY
991
+ if (detectMobileQuick()) {
992
+
993
+ if (!detectTierIphone()) {
994
+
995
+ //The following devices are explicitly ok.
996
+ //Note: 'High' BlackBerry devices ONLY
997
+ //Older Windows 'Mobile' isn't good enough for iPhone Tier.
998
+ if (detectWebkit()
999
+ || detectS60OssBrowser()
1000
+ || detectBlackBerryHigh()
1001
+ || detectWindowsMobile()
1002
+ || userAgent.indexOf(engineTelecaQ) !=
1003
+ -1) {
1004
+ result= true;
1005
+ } // if detectWebkit()
1006
+ } //if !detectTierIphone()
1007
+ } //if detectMobileQuick()
1008
+ return result;
1009
+ }
1010
+
1011
+ /**
1012
+ * The quick way to detect for a tier of devices.
1013
+ * This method detects for all other types of phones,
1014
+ * but excludes the iPhone and RichCSS Tier devices.
1015
+ * @return detection of a mobile device in the less capable tier
1016
+ */
1017
+ public boolean detectTierOtherPhones() {
1018
+ //Exclude devices in the other 2 categories
1019
+ if (detectMobileLong()
1020
+ && !detectTierIphone()
1021
+ && !detectTierRichCss()) {
1022
+ return true;
1023
+ }
1024
+ return false;
1025
+ }
1026
+ }