Is there a way to access android DPI without using JNI?

My Android game uses OpenGL and Android NDK. I am currently passing the required dpi values ​​as parameters, creating my own JNI call from my Activity / GLSurfaceView.

I am currently using:

// request an instance of DisplayMetrics, say 'dm' from android. float densityFactor = dm.density; // pass this as a parameter using JNI call myCustomNativeMethod(densityFactor); # implementation in a 'game.c' file 

I'm just wondering if it's possible to access Android environment settings without using JNI to get them (options). Maybe import some low-level NDK header files (.h) that will help me communicate directly with the user interface system or something like that?

I mean:

  #import <android_displayparams.h> ... float densityfactor = getDisplayParamDensity(); // <- Is this possible? 

Note. This is a question of curiosity, and I know that such a mechanism may not be very good practice.

+4
source share
1 answer

With your setup with Java / GLSurfaceView activity going through DPI, as parameters look like the best solution.

If you use NativeActivity, you can get DisplayMetrics.densityDpi using:

 #include <android/configuration.h> #include <android_native_app_glue.h> #include <android/native_activity.h> int32_t getDensityDpi(android_app* app) { AConfiguration* config = AConfiguration_new(); AConfiguration_fromAssetManager(config, app->activity->assetManager); int32_t density = AConfiguration_getDensity(config); AConfiguration_delete(config); return density; } 

Unfortunately, there is no API to display DisplayMetrics.xdpi and DisplayMetrics.ydpi.

+3
source

All Articles