3

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...

5
  • Can you provide code examples? And if possible maybe an image to show us what you are seeing. Commented Jul 17, 2012 at 14:33
  • I use console.log(screen.width); for logging... Commented Jul 17, 2012 at 14:55
  • 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. Commented Dec 21, 2012 at 13:00
  • Did you find a solution to this problem? My app gives 320x240 but after some time it gives the correct dimensions. Commented Aug 25, 2014 at 11:09
  • 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? Commented Aug 25, 2014 at 11:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.