Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:08:42+00:00 2026-06-17T14:08:42+00:00

I am trying to get the Android DisplayMetrics class in a NativeActivity app using

  • 0

I am trying to get the Android DisplayMetrics class in a NativeActivity app using the NDK. The functions I am trying to call are the ones in these lines:

DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = this.getWindowManager();
Display display = wm.getDefaultDisplay();
display.getMetrics(metrics);

So far, I have gotten the objects setup and the method calls ready as follows

JNIEnv *jni; 
state->activity->vm->AttachCurrentThread(&jni, NULL);
jclass activityClass = jni->FindClass("android/app/NativeActivity");
jclass windowManagerClass = jni->FindClass("android/view/WindowManager");
jclass displayClass = jni->FindClass("android/view/Display");
jclass displayMetricsClass = jni->FindClass("android/util/DisplayMetrics");

jmethodID getWindowManager = jni->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;");
jmethodID getDefaultDisplay = jni->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;");
jmethodID getMetrics = jni->GetMethodID(displayClass, "getMetrics", "(android/util/DisplayMetrics)L;");
jmethodID newDisplayMetrics = jni->GetMethodID(displayMetricsClass, "DisplayMetrics", "()Landroid/util/DisplayMetrics;");

jobject metrics = jni->CallObjectMethod(displayMetricsClass, newDisplayMetrics);
jobject windowManager = jni->CallObjectMethod(state->activity->clazz, getWindowManager);
jobject display = jni->CallObjectMethod(windowManager, getDefaultDisplay);

However, now I do not know how to pass in the metrics jobject to the display.getmetrics() function by reference in order to have the OS adjust it and fill it up correctly, so I can read the fields in it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:08:44+00:00Added an answer on June 17, 2026 at 2:08 pm
    jmethodID getMetrics = jni->GetMethodID(displayClass, "getMetrics", "(Landroid/util/DisplayMetrics;)V");
    jni->CallVoidMethod(display, getMetrics, metrics);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my Android AR app working using the Vuforia SDK. What
I was trying to get the screen resolution of android phones,using this code DisplayMetrics
I'm trying to get the RTSP video stream play in my Android App using
I'm trying to get my Android.mk file to optimize the binaries: LOCAL_PATH := $(call
I'm trying to get an Android app to post highscores to Facebook, similar to
I am trying to get the process name in android by using the method
I'm trying to get the basics of an Android app that sends and receives
I am trying to build a web app for Android device using Senahc Touch
I'm trying to get started with Android development. I'm using eclipse on Linux and
(post updated for working code) I've been trying to get my android app to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.