how to get the screen size in android-jni ?

1,157 views
Skip to first unread message

Shrenik Vikam

unread,
Dec 15, 2010, 4:59:41 AM12/15/10
to android-ndk
I want to get the screen size in pixels for the current android phone
in JNI

Dianne Hackborn

unread,
Dec 15, 2010, 12:20:54 PM12/15/10
to andro...@googlegroups.com
There is no such native API.

The correct thing to do is use the size of a view suppled with Activity.setContentView() after the layout pass.  This tells you the area (both left, top and width, height) where your UI is visible.

Do *not* get the raw display size.  This will not give you want.  There may be system elements on the display and you don't want to include those.

(If you are using the new GB NativeActivity, this has a facility to tell you the content rect you should use.)

On Wed, Dec 15, 2010 at 1:59 AM, Shrenik Vikam <yourso...@gmail.com> wrote:
I want to get the screen size in pixels for the current android phone
in JNI

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Tim Mensch

unread,
Dec 15, 2010, 12:29:06 PM12/15/10
to andro...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/15/2010 2:59 AM, Shrenik Vikam wrote:

> I want to get the screen size in pixels for the current android phone
> in JNI


Unless you're targeting 2.3, the general answer to "how to I do X in
JNI," where "X" involves something to do with Android capabilities as
opposed to how to get C or C++ building or linking, is to "do X in Java
and pass it to your JNI code". There are a few exceptions, and they're
outlined in the JNI docs; the most common reason you can't find
something in the JNI docs (or the headers) is that it's not available in
JNI.

How to do something in Java is the subject of the android-developers
list. I get my surface size by overriding
GLSurfaceView.surfaceChanged(), though the docs tell me I shouldn't
normally subclass that function, so what do I know? :)

Tim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNCPriAAoJENSbqLBCyKKsBKsIALcwy/0g88SuItFv/qAkTrde
yzHBhVxd6skdO7oLPe98uTJUa+kk4EupGCqWxHyISWk6elDxoxeHIa0WgSqefFqf
bIpT9deZknlIWbx5awENs4v+NlmSfcfVaHjtm4RRvUVy7bpEmoaR2H/YfgI+pHS4
TB+GpWG91CeAfNEwl10PES6TpzEw1kR6IcUzVjbm8Ix+HSFV+j0Q3MNyyORSEH3U
1F84OJJwug+6TwPsU/dQX7EZpdm9M5Vqff+q5DvjIFXq6gHQBI3/OiAekX83MQOB
aQi+Y0dHoY24+dlNdI5tkBNl6OMME6n23GCShmhgKWXXkyzThidbr3TSxLoJq40=
=YyXX
-----END PGP SIGNATURE-----

Dianne Hackborn

unread,
Dec 15, 2010, 12:37:47 PM12/15/10
to andro...@googlegroups.com
On Wed, Dec 15, 2010 at 9:29 AM, Tim Mensch <tim.m...@gmail.com> wrote:
How to do something in Java is the subject of the android-developers
list. I get my surface size by overriding
GLSurfaceView.surfaceChanged(), though the docs tell me I shouldn't
normally subclass that function, so what do I know? :)

That's strange, that is a perfectly fine function to subclass.  Wonder why it says that?

Reply all
Reply to author
Forward
0 new messages