/**
         * Gets resolution on old devices.
         * Tries the reflection to get the real resolution first.
         * Fall back to getDisplayMetrics if the above method failed.
         */
        private static Dictionary <int, int> GetRealResolutionOnOldDevice(Context ctx)
        {
            var            dic = new Dictionary <int, int>();
            IWindowManager wm  = ctx.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            //IWindowManager wm = (IWindowManager)ctx.GetSystemService(Context.WindowService);
            try
            {
                Display display = wm.DefaultDisplay;

                var javaObj   = (Java.Lang.Object)display;
                var javaClass = javaObj.Class;
                Java.Lang.Reflect.Method mGetRawWidth  = javaClass.GetDeclaredMethod("Width", new Java.Lang.Class[] { Java.Lang.Boolean.Type });
                Java.Lang.Reflect.Method mGetRawHeight = javaClass.GetDeclaredMethod("Height", new Java.Lang.Class[] { Java.Lang.Boolean.Type });
                mGetRawWidth.Accessible  = true;
                mGetRawHeight.Accessible = true;

                int realWidth  = (int)mGetRawWidth.Invoke(display, new Java.Lang.Object[] { true });
                int realHeight = (int)mGetRawHeight.Invoke(display, new Java.Lang.Object[] { true });
                dic.Add(realWidth, realHeight);
                //Method mGetRawWidth = Display. .class.getMethod("getRawWidth");
                //Method mGetRawHeight = Display.class.getMethod("getRawHeight");
                //Integer realWidth = (Integer)mGetRawWidth.invoke(display);
                //Integer realHeight = (Integer)mGetRawHeight.invoke(display);

                //    return new Pair<>(realWidth, realHeight);
            }
            catch (Java.Lang.Exception e)
            {
                DisplayMetrics dm = new DisplayMetrics();
                wm.DefaultDisplay.GetMetrics(dm);
                dic.Add(dm.WidthPixels, dm.HeightPixels);
            }
            return(dic);
        }
Ejemplo n.º 2
0
 public void UnpairDevice(BluetoothDevice device)
 {
     Java.Lang.Reflect.Method mi = Device.Class.GetMethod("removeBond", null);
     mi.Invoke(device, null);
 }