I want to check this to fetch different images by internet. How to do that?
From the above answers, I combined them and created the below function:
public static String getDeviceDensity(Context context){
String deviceDensity = "";
switch (context.getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
deviceDensity = 0.75 + " ldpi";
break;
case DisplayMetrics.DENSITY_MEDIUM:
deviceDensity = 1.0 + " mdpi";
break;
case DisplayMetrics.DENSITY_HIGH:
deviceDensity = 1.5 + " hdpi";
break;
case DisplayMetrics.DENSITY_XHIGH:
deviceDensity = 2.0 + " xhdpi";
break;
case DisplayMetrics.DENSITY_XXHIGH:
deviceDensity = 3.0 + " xxhdpi";
break;
case DisplayMetrics.DENSITY_XXXHIGH:
deviceDensity = 4.0 + " xxxhdpi";
break;
default:
deviceDensity = "Not found";
}
return deviceDensity;
}
Now, on which device you want to get the density information and which folder it will be used, just add the above method in that activity and add the below line in onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.d("Screen Density: ", Helper.getDeviceDensity(this));
}