Hi guys, I need to get the density DPI of the screen in Android, to make my app to show correctly in all devices.
I searched in the forum and I got that I have to use JNI, bui I don’t know precisely how it works and I am getting some issues… I think i am wrong in something.
In Java I have the displayMetrics library, that works correctly, and I call the code in the onCreate method:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
String packageName = getPackageName();
ofApp = new OFAndroid(packageName,this);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
densityDpi = dm.densityDpi;
System.out.println("Java dpi: " + densityDpi);
this.dpiJNI();
}
public native void dpiJNI();
The console print me correctly tha density in DPI of the screen.
Here is the code to call it in C++ in main.cpp:
extern "C" {
void Java_cc_openframeworks_androidEmptyExample_OFActivity_dpiJNI (JNIEnv* env, jobject thiz, jint densityDpi) {
int dpi = densityDpi;
ofLog(OF_LOG_NOTICE, "javaDPI: " + ofToString(densityDpi));
ofLog(OF_LOG_NOTICE, "DPI: " + ofToString(dpi));
}
}
What I get is a little number (46 for 480dpi screen that I get in Java).
I know I am wrong in something, I think it’s because of my little experience in C++…
Thanks a lot whoever will help (or not) me, maybe it can be helpful for someone else