I'm using Titanium SDK 2.1.3 and I've come across this problem recently, since Android 4.0 and greater can be found in both smartphones and tablets, how can I differentiate between them? If I try to distinguish based on resolutions it wouldn't work right, since some high end smartphones have smaller screens but higher screen resolutions, while some tablets have bigger screens but smaller resolutions.
The app I'm working on work should be displayed in portrait on smartphones, in the case of tablets it should be shown in landscape.
What's the right approach to differentiate between a tablet and a smartphone?
Thanks for any help in advance.
I found a module that calculates the screen size of the device based on the number of pixels per inch, though not 100% accurate it works, this is the link
Related
I'm part of the Android development team at a small company in the city where I live.
We're working on building different apps and currently there's this app we have the design as a .sketch file but the layouts are only drawn for iOS devices and we need to adapt based on those guidelines. The thing is there are 2 different layouts for the iPhone SE and for the iPhone X. They are mainly the same but a few things differ like font sizes, margins, paddings, etc.
I want to implement the design on Android to also be dynamic depending on the user's resolution (or DPI, better said) so I'm trying to use the dimens-xyz.xml files to set my sizes in there and use those values as references in my layouts so I only write one layout xml for each screen, no matter the DPI.
So far, so good. My question is: What are the Android equivalent screen DPIs for the iPhone SE and iPhone X? What dimens-xyz files do I need to use in order to keep the UI consistent for smaller and larger screen devices and have the UI be "responsive".
It's hard to find a relevant answer on Google because it's kind of a technical question and when Google sees iphone and screen in the same search query it starts throwing results of comparing screens for iOS vs Android phones.
PS: I have 0 prior knowledge on iOS development and internals
For iPhone SE, having a 4.7 inch display and 1334 by 750 resolution, you can go with 4.7 WXGA which is a 720 by 1280 equivalent in Android (the closest i could find).
As for Iphone X it has a resolution of 2436×1125, with a 5.8 inch display giving a PPI of 462.63. Closest in Android would be Pixel 3A, with 2220x1080 and 440 dpi.
I have two sizes of 5.1 inches, a 4-inch for 480x800.
When I design in 5.1 screen and run with 4 inch screen, I have some trouble that some button missed position on screen.
I designed by layout.
Android runs on a variety of devices that offer different screen sizes
and densities. For applications, the Android system provides a
consistent development environment across devices and handles most of
the work to adjust each application's user interface to the screen on
which it is displayed.
Please read below Links
Supporting Multiple Screens
How to support multiple screen in Android
How to support different screen size in android
Supporting multiple screen size - Android
Place your view inside a <ScrollView>. Doing so will mean users with smaller devices will be able to scroll the view if it is too large.
I want to develop application with single binary for Android device and for Android tablets with target android 2.1 version.
My orientation also depends upon whether app is running on device or on tablet.
So i just want to know, is there any specification like tablet should be minimum of "X" inches.
There is heaps of information on screen sizes and each device can be different so you should use the Android standards talked about here to figure out exactly what screen you are dealing with and react accordingly. There are no hard and fast "atleast X inches" rules; just different screen sizes of different resolutions. You can use the Android manifest to restrict the screen sizes to just the ones that you want to support.
My orientation also depends upon whether app is running on device or on tablet.
Your application should depend on whether the screen is small, normal, large, or xlarge. There is no concept of "device or on tablet" in Android.
is there any specification like tablet should be minimum of "X" inches.
There is no concept of "tablet" in Android. What a user will think of as a "tablet" will tend to be large or xlarge screen size.
Using Adobe AIR for Android, I'd like to find a way to distinguish a phone from a tablet. The closest I can find is detecting the dpi. (My phone dpi is 254, my tablet is 149) but is that going to be reliable or is there a better way?
(I've been using stackoverflow for a while but this is my first post - yippee!!)
but is that going to be reliable
Absolutely not. A T-Mobile G1 would be a tablet by that measure.
is there a better way?
Frankly, you should not be caring whether an Android device is a telephone, tablet, television, toaster, telescope, or toilet.
You should be caring about characteristics and capabilities.
For example, if you are thinking about tablets in terms of screen size, use <supports-screens> and the -large and -xlarge resource sets (e.g., res/layout/ for normal stuff and res/layout-large/ for larger screen sizes).
Or, if you are thinking about tablets in terms of whether or not you can place a phone call, use <uses-feature> and hasSystemFeature() on PackageManager.
Whether a device is a tablet or not could mean...
One.... Is it running the Honeycomb tablet version (Android 3.0) ? You can use System.getProperty() to get this information.
or
Two....Is it tablet sized? i.e. is the screen a larger size? But bear in mind some tablets are not that big. Best way to handle these is separate resources for each device size.
I'd say in general it's a bad idea to try to define Android tablets into specific groups, as there are many varieties now and a LOT more are coming. So usually best to build your app so it handles different screen sizes, different OS versions, and different features being available or absent (e.g. GPS, keyboard etc).
cdotspace, don't worry about the real dpi, you only need to get virutal dpi:
int virtual_dpi=webview1.getResources().getDisplayMetrics().densityDpi;
Virutal dpi means dots per virtual inch.
For example, the htc desire hd's real width is 2.21 inches, but its virutal width is still 2 inches, the galaxy tab 10.1's real width is 5.35 inches(portrait orient), but its virtual width is 5 inches.
int portrait_width_pixel=Math.min(this.getResources().getDisplayMetrics().widthPixels, this.getResources().getDisplayMetrics().heightPixels);
int dots_per_virtual_inch=this.getResources().getDisplayMetrics().densityDpi;
float virutal_width_inch=portrait_width_pixel/dots_per_virtual_inch;
if (virutal_width_inch<=2)
{//is phone
}
else
{//is tablet
}
I want to make sure that devices with 10,1" and 1024x600 under 2.1/2.2(e.g. Archos 101) are using the correct layout.
Are they large and ldpi?
Also, how can I simulate them using the android emulator?
In the end, the choices of screen size and screen density are up to the manufacturer. Hence, nobody here can answer you definitively.
A 10.1" diagonal screen should be large and probably should be ldpi, though it is possible it will be declared mdpi based upon the apparent density given the distance one would typically hold a 10.1" tablet from one's face.
Bear in mind that ARCHOS' devices do not ship with the Android Market AFAIK, and hence do not necessarily pass the various compatibility tests. As a result, ARCHOS could do all sorts of stuff that would be unexpected.
Also, how can I simulate them using the android emulator?
The Android SDK is not well-suited for testing a 10.1" LCD at this time. I would expect better instructions and support for such sizes in Android 3.0.
For now, set the resolution and density for the AVD when you create it. In this case, you would want to specify 120dpi (ldpi) for the density. Android should put it in the large screen size bucket for you, given those values. Leastways, that basic approach works for getting large WVGA devices.