We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all! I am working on an android app and need to get screen size in cm to make it compatible with all devices. For that, I found this function in another discussion:
import android.view.WindowManager;
import android.util.DisplayMetrics;
import android.os.Bundle;
DisplayMetrics metrics;
//code like setup and draw etc.
//@Override
void onCreate(Bundle bundle)
{
super.onCreate(bundle);
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
float getXdpi()
{
return metrics.xdpi;
}
float getYdpi()
{
return metrics.ydpi;
}
However, when I paste it to my code, the getWindowManager.getDefaultDisplay.getMetrics(metrics) gets underlined, specifically the getWindowManager part and it says that such a function does not exist.
What could be the problem?
Answers
@randomdude===
of course: this code is for an activity and since 3.0 you are in a fragment...
@akenaton how can I get the screen of my device’s xdpi and ydpi then? Please help.
@randomdude===
working hard today tomorrow i ll'explain with some snippet
@akenaton
Take your time. I am waiting with baited breath. :)
https://forum.processing.org/two/discussion/24347/how-to-get-actual-size-of-screen-in-android-mode#latest