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

后端 未结 3 1710
挽巷
挽巷 2020-12-23 16:13

So i have a small problem, i\'m writing a function which need to send screen width to server. I got it all to work, and i use:

Display display = getWindowMan         


        
3条回答
  •  既然无缘
    2020-12-23 16:45

    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);
    }
    

提交回复
热议问题