Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Device density is returned as zero from some devices

Tags:

android

The device density return 0 from some devices. The following code is used to calculate device density:

WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
density = metrics.density;

This has resulted in some crashes in PlayStore. The users seem to be using: Galaxy Y Plus ; Android version 4.0.3 - 4.0.4. Also a device called wing-k70 had problems. In one crash it was version 4.2.

Please advice.

like image 940
Jean Avatar asked Jan 12 '15 07:01

Jean


1 Answers

There is not much you can do other than handle this gracefully. If density is null or 0 check for it and use a default value in this case.

like image 193
DKIT Avatar answered Oct 28 '22 04:10

DKIT