Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:51:42+00:00 2026-05-25T09:51:42+00:00

In the course of developing my Android application, I noticed that the following lines

  • 0

In the course of developing my Android application, I noticed that the following lines of code were not reporting the correct screen size for my Samsung Nexus S:

width = getResources().getDisplayMetrics().widthPixels;
height = getResources().getDisplayMetrics().heightPixels;

Width was returned as 320, while height got set to 533. From this post I know that this is a problem relating to the pixel density of the device not being taken into account. To correct for this, I wrote up the code below:

DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(dm);

int density = dm.densityDpi; 
int width = (density / 160) * dm.widthPixels; 
int height = (density / 160) * dm.heightPixels;

When I toast the variables width and height, the returned dimensions are 320 wide and 533 tall, meaning that nothing changed. Furthermore, dm.densityDpi returns 160, and not 235, as it should for the Samsung Nexus S.

Some posts that I have read, seem to suggest that the problem might lie within the AndroidManifest.xml. I have already added the following to my XML file in an attempt to solve this issue:

<uses-sdk 
    android:minSdkVersion="7" 
    android:targetSdkVersion="10"
/>

<supports-screens 
    android:anyDensity="false"
    android:resizeable="false"
    android:largeScreens="true"
    android:normalScreens="true"
/>

But, alas, this has not worked either. So, does anyone know how I can get the phone to correctly return its density?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:51:42+00:00Added an answer on May 25, 2026 at 9:51 am

    This “problem” has nothing to do with density, it’s because your application runs in compatibility mode. Your manifest must report anyDensity=true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a C++ application that is extended/ scriptable with Python. Of course C++
I'm developing a Python application; it has all its code in one package and
I am developing a Rails3 application using Devise for authentication. In the course of
I'm developing a website that has some audio courses, each course can have multiple
I'm developing a website that has some audio courses, each course can have multiple
I'm developing an Android application. I have my activity here with some widgets including
I'm developing PHP apps that leverage several frameworks (though not the Zend Framework yet...)
I'm developing an Android app that absolutely needs to support Android 2.1+ devices, including
I'm developing an IPad application that use a prefeatched database with a synchronisation feature
I'm developing a Rails-3.1 Mountable Engine that would be mounted in a rails application,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.