Is it safe to use .getWidth on Display even though its deprecated

You can check for API level at runtime, and choose which to use, e.g.:

final int version = android.os.Build.VERSION.SDK_INT;
final int width;
if (version >= 13)
{
    Point size = new Point();
    display.getSize(size);
    width = size.x;
}
else
{
    Display display = getWindowManager().getDefaultDisplay(); 
    width = display.getWidth();
}

If you want to be correct, use this approach:

int sdk = android.os.Build.VERSION.SDK_INT;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
} else {
    Point size = new Point();
    display.getSize(size);
}

May be this approach will be helpful:

DisplayMetrics displaymetrics = new DisplayMetrics();
mContext.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenWidth = displaymetrics.widthPixels;
int screenHeight = displaymetrics.heightPixels;

Here is the latest Code without Deprecation.

Kotlin

 val metrics: DisplayMetrics = this.getResources().getDisplayMetrics()
 val width = metrics.widthPixels

Java

  DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  int width = metrics.widthPixels;
  int height = metrics.heightPixels;