Page 1 of 2
Way to get display resolution
Posted: 23 Sep 2017 19:50
by acerzw
IT would be useful to have an action or function to return the screen X and y resolution in pixels
Re: Way to get display resolution
Posted: 24 Sep 2017 03:37
by Desmanto
I would just use terminal command to retrieve the resolution. It should be available on most android, especially Lollipop 5.0 above.
Action :
Execute Command
Command :
wm size
just leave everything default. If the resolution is Full HD, The stdout (output of command), should be
Physical size: 1080x1920
From here, we wanna extract out the width and the height. Use script to parse the resolution. There are other ways to do it, but it is easier to use regex.
Code: Select all
res = findAll(stdout, "Physical size: (\\d+)x(\\d+)", true);
width = res[0][1];
height = res[0][2];
(\\d+) will match one or more digit and capture it as group (the bracket capture it). The result of capture is stored at index [0][1] and [0][2]. Use the {width} and {height} as needed.
You can also use command
wm density to get the density (dpi).
Re: Way to get display resolution
Posted: 24 Sep 2017 07:53
by acerzw
Thanks that's great.
Re: Way to get display resolution
Posted: 24 Sep 2017 12:19
by Bingwu
Hello Desmanto!
I also wanted to try your suggestion!
I get the following error message (stderr) in the
Execute Command (wm size):
Code: Select all
Error type 2
android.util.AndroidException: Can't connect to window manager; is the system running?
at com.android.commands.wm.Wm.onRun(Wm.java:81)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
at com.android.commands.wm.Wm.main(Wm.java:46)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:301)
Am I doing something wrong

or can it be that it does not work on Android 7?
Tested with:
Samsung Galaxy S7 edge, Android 7.0, Stock-ROM, non rooted
Asus Nexus 7 (2. Gen.), Android 7.1.2, LineageOS, rooted
Regards
Peter
Re: Way to get display resolution
Posted: 24 Sep 2017 12:48
by acerzw
You know I also got the same on my Samsung t285 Tab A 7" (rooted lineage OS 7.12)
Re: Way to get display resolution
Posted: 24 Sep 2017 13:51
by bogdyro
Hi,the command works using root.
(execute root command)
Re: Way to get display resolution
Posted: 24 Sep 2017 14:14
by bogdyro
You can do it without root by using Java.
Check the attached flow.
Maybe Martin could implement it as a separate action.
http://automagic4android.com/flow.php?i ... b61d92766e
Re: Way to get display resolution
Posted: 24 Sep 2017 16:24
by Desmanto
@Bingwu : Don't know what's wrong. Try to install terminal emulator and type the command directly to see if it works at there. But seems using java is more general; as the function to retrieve it must be available on every android out there (if not, it will be less useful then)
@bogdyro : How can you get until that?

That is nesting so many parameter. I don't know we have to nest it so many times to get something like this. That explains why I mostly failed to use the java function. Wish I have know more about java. This should have work better that using execute command.
Re: Way to get display resolution
Posted: 24 Sep 2017 19:06
by Bingwu
Hello bogdyro and Desmanto!
Thanks for your help!
@bogdyro: Your flow (action) I have tested on my Asus Nexus 7. It unfortunately gives me an incorrect value for the display height (1824 instead of 1920). The display width is correct (1200).
It is also not a problem, it would have been a practical feature!
Regards
Peter
Re: Way to get display resolution
Posted: 25 Sep 2017 02:34
by Desmanto
That is correct. If you rotate it to landscape, the height will be correct, 1920, while the width will become less (probably 1104). 96 pixel reduction is from on screen navigation button (recent, home, back).