扣丁书屋

获取带虚拟按键手机的屏幕分辨率

2年以前  |  阅读数:256 次  |    

public static String getDisplay(Context context )
    {
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager manager = (WindowManager)context.getSystemService( Context.WINDOW_SERVICE );
        Display display = manager.getDefaultDisplay();
        display.getMetrics( metrics );
        DisplayMetrics dm = new DisplayMetrics();
        @SuppressWarnings( "rawtypes" )
        Class c;
        try
        {
            c = Class.forName( "android.view.Display" );
            @SuppressWarnings( "unchecked" )
            Method method = c.getMethod( "getRealMetrics" , DisplayMetrics.class );
            method.invoke( display , dm );
            return dm.widthPixels + "*" + dm.heightPixels;
        }
        catch( Exception e )
        {
            return metrics.widthPixels + "*" + metrics.heightPixels;
        }
    }

相关文章: