3
votes

After launching app with "deviceready" event, my Phonegap app on Android returns false screen.width (window.innerWidth is the same) values on ZTE Blade (native 800px). I get width values like 320, 533 or 787 px, sometimes different values within one app instance (launch) when asking multiple times...

I have android:screenOrientation="landscape" in my AndroidManifest.xml. Using Phonegap/Cordova 1.8.1 in Eclipse (Indigo).

Some sample values of screen.width:

in index.html

  • before document.addEventListener+"deviceready": 320
  • just after "deviceready": 320

then redirect three times (change window.location to different HTML file) because of 2 splash-screens and finally land to main.html. I include my .js code in every file just for debugging, and get 3 console.logs:

  1. 320
  2. 787
  3. 787

Very strange...

1
Can you provide code examples? And if possible maybe an image to show us what you are seeing. - Kris Hollenbeck
I use console.log(screen.width); for logging... - Kozuch
I suspect the window.location change could be the problem (redirecting to another html files within one app). Recently I had problems with sound which I solved by abandoning the location redirects and incorporating everything into single HTML file. - Kozuch
Did you find a solution to this problem? My app gives 320x240 but after some time it gives the correct dimensions. - cherouvim
I can not really remember how I solved this. I most likely put it aside because I was not really in a hurry for a solution since the device (ZTE Blade) was not a reference one but a Samsung Galaxy Tab 10.1 was. However I never encountered this problem again after several PhoneGap/Cordova upgrades and also phone upgrades (both HW&SW) - I now develop on Cordova 3.5 on Samsung Galaxy S3 mini (GT-I8190). I guess this might have been a bug within Cordova since I guess they did not really care about old Android versions (Blade had 2.1-2.3). What is your HW & SW configuration? - Kozuch

1 Answers

2
votes

There's a comprehensive article (+ comparison tables of different values) that you should read: http://tripleodeon.com/2011/12/first-understand-your-screen/

Hope this helps with your issue.