AConfiguration_getDensity() delivers strange results

536 views
Skip to first unread message

Andreas Falkenhahn

unread,
Jan 3, 2013, 3:58:05 PM1/3/13
to andro...@googlegroups.com
Hi,

I want my app to use different designs depending on the DPI of the target
device. Thus, I'm trying to find out the screen density. The Android NDK
function AConfiguration_getDensity() seems to return strange values, though:

- On my Samsung smart phone that has a resolution of 480x800 but a very small
screen I get ACONFIGURATION_DENSITY_HIGH (running Android 2.3)

- On my Acer tablet that has a resolution of 1024x768 on a pretty large screen
I get only ACONFIGURATION_DENSITY_MEDIUM (running Android 4.0)

So the density seems to be pretty unreliable but I cannot find a different
way to find out the screen DPI. Any ideas?

Tks,

Andreas

Thomas Martitz

unread,
Jan 3, 2013, 4:56:44 PM1/3/13
to andro...@googlegroups.com
The Acer tablet has indeed a lower DPI, since its screen size (diagonal
in inch) is much larger while the resolution is only a bit larger. You
can calculate the real DPI with sqrt(x^2+y^2)/diagonal in inch.

Additionally Android rounds the DPI to match one of the predefined "DPI
buckets" which translates to DENSITY_HIGH and DENSITY_MEDIUM (among others).

Read more on:
http://developer.android.com/guide/practices/screens_support.html

Best regards.

Andreas Falkenhahn

unread,
Jan 4, 2013, 7:24:54 AM1/4/13
to Thomas Martitz, andro...@googlegroups.com
On 03.01.2013 at 22:56 Thomas Martitz wrote:

> Am 03.01.2013 21:58, schrieb Andreas Falkenhahn:
>> Hi,

>> I want my app to use different designs depending on the DPI of the target
>> device. Thus, I'm trying to find out the screen density. The Android NDK
>> function AConfiguration_getDensity() seems to return strange values, though:

>> - On my Samsung smart phone that has a resolution of 480x800 but a very small
>> screen I get ACONFIGURATION_DENSITY_HIGH (running Android 2.3)

>> - On my Acer tablet that has a resolution of 1024x768 on a pretty large screen
>> I get only ACONFIGURATION_DENSITY_MEDIUM (running Android 4.0)

>> So the density seems to be pretty unreliable but I cannot find a different
>> way to find out the screen DPI. Any ideas?


> The Acer tablet has indeed a lower DPI, since its screen size (diagonal
> in inch) is much larger while the resolution is only a bit larger. You
> can calculate the real DPI with sqrt(x^2+y^2)/diagonal in inch.

Thanks for the clarification, but where do I get the "diagonal" value from?
And what is "x" and "y"? Screen width and height in pixels?

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com

Thomas Martitz

unread,
Jan 4, 2013, 12:07:27 PM1/4/13
to andro...@googlegroups.com
Am 04.01.2013 13:24, schrieb Andreas Falkenhahn:
> Thanks for the clarification, but where do I get the "diagonal" value
> from? And what is "x" and "y"? Screen width and height in pixels?

You can measure the diagonal with a rule, but it's probably written
somewhere. It's the screen size the devices are advertised with (e.g.
the Nexus 7 has a well known screen size of 7").

Yes, with x and y I actually meant width and height in pixels.

Best regards.

Andreas Falkenhahn

unread,
Jan 4, 2013, 2:41:06 PM1/4/13
to Thomas Martitz, andro...@googlegroups.com
On 04.01.2013 at 18:07 Thomas Martitz wrote:

> Am 04.01.2013 13:24, schrieb Andreas Falkenhahn:
>> Thanks for the clarification, but where do I get the "diagonal" value
>> from? And what is "x" and "y"? Screen width and height in pixels?

> You can measure the diagonal with a ruler, but it's probably written
> somewhere. It's the screen size the devices are advertised with (e.g.
> the Nexus 7 has a well known screen size of 7").

Um, I meant programmatically with the NDK of course... I do know
how to use a ruler but this is impossible for devices which aren't
physically in my hands :)
Reply all
Reply to author
Forward
0 new messages