I have such a problem: I'm writing application for Android using Adobe AIR 2.6 and Flash Builder 4.5. I need to scale my resources depending on mobile device resolution. For this purpose I need to know device resolution and DPI. I'm using such a code to get it:
PlatformUtil.init(mainView.stage.stageWidth, mainView.stage.stageHeight,
Capabilities.screenDPI, mainView);
When I run this code on device - all OK! All resources scaled properly (on Nexus One). But when I run it on my desctop computer on flash builder simulator, and choose from devices Google Nexus One - it must have resolution 800*480, but in code I get actual size 500*375. When I'm using Capabilities class, it returns me 1024*768 (my desctop resolution). So, whats wrong with it? Why it returns me wrong device resolution? How can I solve this problem? Thanx for help.
I solved this issue. Simulator returns valid simulator screen resolution in handler on Event.RESIZE, this can be done like this:
public class Main extends Sprite
{
public function Main()
{
super();
//register to add to stage
this.stage.addEventListener(Event.RESIZE, onResize);
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onResize(event:Event):void
{
this.stage.removeEventListener(Event.RESIZE, onResize);
//width must be bigger then height, because we in landscape mode
var w:int = Math.max(this.stage.stageWidth, this.stage.stageHeight);
var h:int = Math.min(this.stage.stageWidth, this.stage.stageHeight);
//draw black background
with( graphics )
{
beginFill(0x0)
drawRect(0,0,w,h);
}
init();
}
}
Hope it will help someone like me.