I was using getRealMetrics() method and came to know that it is deprecated
val display = this.display
display?.getRealMetrics(outMetrics)
anybody know what is the alternative.
I was using getRealMetrics() method and came to know that it is deprecated
val display = this.display
display?.getRealMetrics(outMetrics)
anybody know what is the alternative.
 
    
     
    
    try this
Resources.getSystem().displayMetrics
For width and height
Resources.getSystem().displayMetrics.widthPixels
Resources.getSystem().displayMetrics.heightPixels
 
    
    https://developer.android.com/reference/android/view/Display
getRealMetrics(DisplayMetrics outMetrics)
This method was deprecated in API level 31. Use WindowManager#getCurrentWindowMetrics() to identify the current size of the activity window. UI-related work, such as choosing UI layouts, should rely upon WindowMetrics#getBounds(). Use Configuration#densityDpi to get the current density.
 
    
    Use WindowMetricsCalculator to get display height and width parameter
dependencies {
implementation "androidx.window:window:1.0.0-beta02"}
val windowMetrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(activity)
val currentBounds = windowMetrics.bounds
val width = currentBounds.width()
val height = currentBounds.height()
 
    
    Hi i create this function in xamarin.android: (manifest SDK max 31, min 25)
public bool IsTablet()
    {
        var displayMetrics = Resources.DisplayMetrics;
        var defaultDisplay = WindowManager.DefaultDisplay;
        double widthPixels = 0;
        double heightPixels = 0;
        if (Build.VERSION.SdkInt >= BuildVersionCodes.S) //API 31 and more
        {
            var windowMetrics = WindowManager.CurrentWindowMetrics;
            Rect bounds = windowMetrics.Bounds;
            widthPixels = bounds.Width();
            heightPixels = bounds.Height();   
        }
        if (Build.VERSION.SdkInt == BuildVersionCodes.R) //API 30
        {
            #pragma warning disable
            defaultDisplay.GetRealMetrics(displayMetrics);
            widthPixels = displayMetrics.WidthPixels;
            heightPixels = displayMetrics.HeightPixels;
        }
        if (Build.VERSION.SdkInt < BuildVersionCodes.R) //less then 30
        {
            #pragma warning disable
            defaultDisplay.GetMetrics(displayMetrics);
            widthPixels = displayMetrics.WidthPixels;
            heightPixels = displayMetrics.HeightPixels;
        }
        var wInches1 = widthPixels / (double)displayMetrics.DensityDpi;
        var hInches1 = heightPixels / (double)displayMetrics.DensityDpi;
        double inch = Math.Sqrt(Math.Pow(wInches1, 2) + Math.Pow(hInches1, 2));
        if (cale >= 7.0)
        {
            tablet = true;
        }
        return tablet;
    }
