Peter Young
Peter Young

Reputation: 31

Android: How do I get the device DPI from native code

We are developing an Android application based on our existing native library. We have a set JNI classes to expose the native APIs.The native library has a DPI global static variable need to be initialized in the this block:

JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt ) {
 ...
}

The question is that how do I get the device DPI on native level. I know that on Java level you can easily get the property by WindowManager once activity is up. Is it possible to get the property before my activity startup?

Appreciate your help.

Upvotes: 3

Views: 652

Answers (1)

Ihar
Ihar

Reputation: 325

As I remember, you need to have Context to get DPI, but in native code you have not. I recommend you to add a native method which will be called in Application.onCreate and set your native variable. This will be done not in JNI_OnLoad but before any activity starts.

Upvotes: 1

Related Questions