Resoution discrepency

Android_Zippy

Member
Feb 4, 2013
13
0
0
Visit site
This one's driving me nuts.

I'm writing an app and have been testing it on my nice shiny new N10 - but my app is reporting the screen resolution as 2464 * 1600 ??!!

It's not the code as far as I can see as it returns the correct resolution on multiple handsets - just not my N10.

Anyone know where my missing 96 pixels went? I've Google'd this like crazy, but not come up with anything yet :-X

PS Lovin' the N10 - best purchase I've made over the last year!
 

Craig King

Well-known member
Nov 17, 2012
253
0
0
Visit site
Just a thought but could it be the pixels on the bottom of the screen for the navigation bar controlls and such.
 
Last edited:

zkSharks

Retired Moderator
Mar 15, 2011
2,013
75
0
Visit site
The resolution available to your application itself will be the current statusbar and navbar height subtracted from the full current height. On a device running the tablet UI, they are typically combined at the bottom. If you'd like the application to run in a full-screen mode, try one of the following:

In your manifest:

Code:
  <application
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

You can also declare this at the activity level in your manifest, if you only want specific activities to run fullscreen.

Alternatively, in your activity's onCreate:

Code:
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Call these two methods after super.onCreate() and before setContentView().
 

Android_Zippy

Member
Feb 4, 2013
13
0
0
Visit site
Hey, thanks for the suggestions, unfortunately, I'm already running without status bar - but maybe there's something else I need to do in Jelly bean? I mean a phone with a 800 x 480 res is reporting exactly that once running without status bar, but the nexus, doesn't - it's really odd. The bar does disappear. (I am using the first method, application level declaration in the manifest)
 

zkSharks

Retired Moderator
Mar 15, 2011
2,013
75
0
Visit site
Hey, thanks for the suggestions, unfortunately, I'm already running without status bar - but maybe there's something else I need to do in Jelly bean? I mean a phone with a 800 x 480 res is reporting exactly that once running without status bar, but the nexus, doesn't - it's really odd. The bar does disappear. (I am using the first method, application level declaration in the manifest)

Unfortunately I won't have access to my Nexus 10 for a few days, so I can't do any specific testing for you. If your goal here is simply to get information pertaining to the display itself (such as physical resolution), I would look at using the DisplayMetrics class.

Code:
  DisplayMetrics metrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(metrics);

You should be able to use public int heightPixels and public float ydpi do perform basic calculations, but I should caution you that if this application is intended for more than personal use (i.e. it will be distributed, via the Play Store or other channels), carrying out actions based on the display's physical dimensions may lead to fragmentation issues similar to the one you're already trying to solve.

Additionally, there are methods of determining the height of the statusbar/navbar on the screen, which theoretically could be used in conjunction with the above code for accessing the display size in order to determine the remaining space for your application. But again, I should note that you may run into fragmentation issues when you start relying on such calculations.
 

Android_Zippy

Member
Feb 4, 2013
13
0
0
Visit site
Thanks mate, I'm using a similar method - but I will try the code you posted. I'm passing it from my activity into my SurfaceView class and using it for a full screen canvas. I need to do it this way as I need to know what size the canvas is going to be before it's been created (for created scaled bitmaps etc). It will be published on the Play Store eventually. It just kind of threw me because every other device I've tested it on returns the correct device resolution. Strange! :-\
 

Forum statistics

Threads
943,167
Messages
6,917,624
Members
3,158,858
Latest member
AmeliaRodriguez