How to check the weather on the device - iPad and tablet in the phone

How to check the device on the phone ?. In fact, I need my application to run only on the tablet or on the Iphone. I need to block my application on other phones, only by launching an Android tablet or iphone Ipad.is can I check PhoneGap? ..

thanks

+2
source share
3 answers

Introduction

There are several solutions available. Some of them are provided by javascript, some are free, and some are paid. In addition, some of them are server-side and some are client-side, but from this mail I think you need client-side solutions.

Client Side Discovery:

Modernizer -

The benefit of cool new web technologies is great fun, as long as you don't have to support browsers that are lagging behind. Modernizr makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether the browser supports the function or not. Ideal for progressive improvement easily.

Good:

Client side only, server side component does not exist

Fast but still great for javascript framework with its 12kb. Due to its modularity, it can become smaller, depending on your needs.

Bad:

It can only do so much less information than server-side discovery.

Modernizr itself is a great way to find out about the capabilities of the user's browser. However, you can only access your API in the browser itself, which means that you cannot easily find out about the capabilities of the browser in your server logic.

Example:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Modernizr Example</title> <script src="modernizr.min.js"></script> </head> <body> <script> if (Modernizr.canvas) { // supported } else { // no native canvas support available :( } </script> </body> </html> 

JavaScript Bypass

It can be argued that this may be the (academically) worst way to detect mobile devices, but it has its merits.

Good:

Plain

Bad:

It will indicate only the type of device, but there will be no version of the device. For example, he will tell you that we used the iPad, but not if it is version 1.2 or 3.

Example:

 <script type="text/javascript"> var agent = navigator.userAgent; var isWebkit = (agent.indexOf("AppleWebKit") > 0); var isIPad = (agent.indexOf("iPad") > 0); var isIOS = (agent.indexOf("iPhone") > 0 || agent.indexOf("iPod") > 0); var isAndroid = (agent.indexOf("Android") > 0); var isNewBlackBerry = (agent.indexOf("AppleWebKit") > 0 && agent.indexOf("BlackBerry") > 0); var isWebOS = (agent.indexOf("webOS") > 0); var isWindowsMobile = (agent.indexOf("IEMobile") > 0); var isSmallScreen = (screen.width < 767 || (isAndroid && screen.width < 1000)); var isUnknownMobile = (isWebkit && isSmallScreen); var isMobile = (isIOS || isAndroid || isNewBlackBerry || isWebOS || isWindowsMobile || isUnknownMobile); var isTablet = (isIPad || (isMobile && !isSmallScreen)); if ( isMobile && isSmallScreen && document.cookie.indexOf( "mobileFullSiteClicked=") < 0 ) mobileRedirect(); </script> 

More details

I have another article / answer on this topic. Find HERE .

+6
source

You can do this using JavaScript using the User Agent, as already explained in another answer,

But you can also use the Cordova / PhoneGap Device API

http://cordova.apache.org/docs/en/2.8.0/cordova_device_device.model.md.html#device.model

Using var string = device.model;

Line

will contain an iOS model

Providing you with all the information from the native only if you want to find out if there is an iPad 1, iPad 2 or iPad Mini

For example, iPad2.5 is an iPad Mini Wifi

Check this site for information http://theiphonewiki.com/wiki/Models

+4
source

Cordoba out of the box cannot determine if the device is a tablet.

For iOS, a simple Javascript bit can be used to determine if an iPad is by examining the user agent string:

 var isTablet = !!navigator.userAgent.match(/iPad/i); 

However, for Android, JS is not good enough; it requires some native Java:

 private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; } } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; } 

This plugin includes both of these approaches in an easy-to-use package for Android and iOS: https://github.com/dpa99c/phonegap-istablet .

+1
source

Source: https://habr.com/ru/post/1483395/


All Articles