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 5932885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:48+00:00 2026-05-22T14:53:48+00:00

I have a small class that needs to keep track of the devices width

  • 0

I have a small class that needs to keep track of the devices width and height.

public class BrScreenMetrics {
public static int screenX=0;
public static int screenY=0;

public static void setMetrics(Activity activity)
{ 

    WindowManager w = activity.getWindowManager();
    Display d = w.getDefaultDisplay(); 
    screenX = d.getWidth(); 
    screenY = d.getHeight(); 


}

}

With each new activity i unvoke the line:

BrScreenMetrics.setMetrics(this);

which updates the values on rotation etc… This works great, except that it is returning 320×522, not my desire’s 480×800.
What am i doing wrong?

Slight Update:

I tried it with this code as well using androids own metrics class:

    public static void setMetrics(Activity activity)
{ 
   DisplayMetrics metrics = new DisplayMetrics();
   activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);      
   screenX = metrics.widthPixels;
   screenY = metrics.heightPixels;

}

but it is still 320×522 🙁

  • 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-22T14:53:49+00:00Added an answer on May 22, 2026 at 2:53 pm

    Thanks looking into the manifest was indeed the right way, I found out in the end i needed

    with a minimum requirement of 4-6.

    Here is my utility if anyone finds it useful or can offer ways to make it better:

    package se.brickit.foundation;
    //Open comment block above for info.
    
    import android.app.Activity;
    import android.view.Display;
    import android.view.WindowManager;
    import android.webkit.WebSettings.ZoomDensity;
    
    public class BrScreenMetrics {
        private static int screenWidthPX = 0;
        private static int screenHeightPX = 0;
        private static int densityDpi = 0;
        private static DisplayMetrics metrics;
    
        public static void setMetrics(Activity activity) {
            DisplayMetrics metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
            screenWidthPX = metrics.widthPixels;
            screenHeightPX = metrics.heightPixels;
            densityDpi = metrics.densityDpi;
    
        }
    
        /**
         * @return the screenWidthPX
         */
        public static int getScreenWidthPX() {
            return screenWidthPX;
        }
    
        /**
         * @param screenWidthPX
         *            the screenWidthPX to set
         */
        public static void setScreenWidthPX(int screenWidthPX) {
            BrScreenMetrics.screenWidthPX = screenWidthPX;
        }
    
        /**
         * @return the screenHeightPX
         */
        public static int getScreenHeightPX() {
            return screenHeightPX;
        }
    
        /**
         * @param screenHeightPX
         *            the screenHeightPX to set
         */
        public static void setScreenHeightPX(int screenHeightPX) {
            BrScreenMetrics.screenHeightPX = screenHeightPX;
        }
    
        /**
         * @return the densityDpi
         */
        public static int getDensityDpi() {
            return densityDpi;
        }
    
        /**
         * @param densityDpi
         *            the densityDpi to set
         */
        public static void setDensityDpi(int densityDpi) {
            BrScreenMetrics.densityDpi = densityDpi;
        }
    
        /**
         * @return the metrics
         */
        public static DisplayMetrics getMetrics() {
            return metrics;
        }
    
        /**
         * @return the density
         */
        public static ZoomDensity getZoomDensity() {
            if (densityDpi < 140)
                return ZoomDensity.CLOSE;
            if (densityDpi < 210)
                return ZoomDensity.MEDIUM;
            return ZoomDensity.FAR;
        }
    
        public static int getStatusBarHeight() {
            ZoomDensity zd = getZoomDensity();
    
            if (zd == ZoomDensity.CLOSE)
                return 19;
            else if (zd == ZoomDensity.MEDIUM)
                return 25;
            else 
                return 38;
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a not-so-small class under development (that it changes often) and I need
I have a small class that displays an alert via Javascript. I am using
I have this small class called City that simply holds some information about a
So I have a small C# app that needs to periodically check the contents
I have small class called 'Call' and I need to store these calls into
I have a small class hierarchy where I would like to have a child
I have a small Java test app in Netbeans where the main() class reads
I have a class which has many small functions. By small functions, I mean
I'm coding a small class that maximizes a given function F and returns the
I have a WPF app that from time to time needs to perform a

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.