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

  • SEARCH
  • Home
  • 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 5992719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:34:23+00:00 2026-05-22T23:34:23+00:00

I have read http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/reference/android/util/DisplayMetrics.html and I somehow left with a gap here.

  • 0

I have read http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/reference/android/util/DisplayMetrics.html and I somehow left with a gap here.

  1. How is the transition from DisplayMetrics.densityDpi to for example String ("ldpi") done?
  2. And more importantly from DisplayMetrics.widthPixels and DisplayMetrics.widthPixels to for example String ("large")

For the first I can whip up a switch statement easy enough. But the 2nd one is quite more complex. Does anybody know any details? Is there a function which does it?

I even searched the source and did not find anything. But maybe i looked for the wrong thing.

  • 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-22T23:34:23+00:00Added an answer on May 22, 2026 at 11:34 pm

    I figured it out, here the correct code (you need a valid android.content.Context instance in attribute context):

         final android.view.WindowManager windowManager =
            (android.view.WindowManager) this.context
               .getSystemService (android.content.Context.WINDOW_SERVICE);
         final android.util.DisplayMetrics metrics = new android.util.DisplayMetrics ();
         final android.content.res.Resources resources = this.context.getResources ();
         final android.content.res.Configuration config = resources.getConfiguration ();
    
         windowManager.getDefaultDisplay ().getMetrics (metrics);
    
         final int density = metrics.densityDpi;
         final int size =
            config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK;
         final String densityText;
         final String sizeText;
    
         switch (density)
         {
            case android.util.DisplayMetrics.DENSITY_LOW:
            {
               densityText = "ldpi";
               break;
            }
            case android.util.DisplayMetrics.DENSITY_MEDIUM:
            {
               densityText = "mdpi";
               break;
            }
            case android.util.DisplayMetrics.DENSITY_HIGH:
            {
               densityText = "hdpi";
               break;
            }
            case android.util.DisplayMetrics.DENSITY_XHIGH:
            {
               densityText = "xhdpi";
               break;
            }
            default:
            {
               densityText = "unknown";
               break;
            }
         } // switch
    
         switch (size)
         {
            case android.content.res.Configuration.SCREENLAYOUT_SIZE_SMALL:
            {
               sizeText = "small";
               break;
            }
            case android.content.res.Configuration.SCREENLAYOUT_SIZE_NORMAL:
            {
               sizeText = "normal";
               break;
            }
            case android.content.res.Configuration.SCREENLAYOUT_SIZE_LARGE:
            {
               sizeText = "large";
               break;
            }
            case android.content.res.Configuration.SCREENLAYOUT_SIZE_XLARGE:
            {
               sizeText = "xlarge";
               break;
            }
            default:
            {
               sizeText = "unknown";
               break;
            }
         } // switch
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read http://developer.android.com/reference/android/app/Activity.html but I have a question about PreferenceActivity lifecycle: Does a PreferenceActivity
Ok so I've read the Custom Dialog explanation on the And Dev website http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Quick note: I'm using the SoundPool class http://developer.android.com/reference/android/media/SoundPool.html What I have here is a
I read this http://developer.android.com/resources/tutorials/notepad/index.html and now try to create my own simple example. For
I have read the Apple docs - http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW1 about creating TabBar programmatically. I want
i've just downloaded the Yahoo BOSS Mashup framework from http://developer.yahoo.com/search/boss/mashup.html , and I have
I have read the GOLD Homepage ( http://www.devincook.com/goldparser/ ) docs, FAQ and Wikipedia to
I read carefully the good UI practice from the Google Dev Blog; http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html and
I want to access/add/read etc google calender from my Android program. I have tried
I was reading this paper from Apple: http://developer.apple.com/library/mac/documentation/cocoa/conceptual/OOP_ObjC/OOP_ObjC.pdf where it talks about OOP which

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.