locked
Get WindowManager using GetSystemService. Where is the class WindowManager? RRS feed

  • Question

  • User19848 posted

    Hello,

    I want to use the Context.GetSystemservice(Context.WindowService) method to get the WindowManager. After some search I have found that there is no WindowManager (at least exposed to the developer) but only when you are in an Activity you can get the IWindowManager and access what you need properly.

    I want to accomplish this in a class library when only have the ApplicationContext and the GetSystemService(Context.WindowService) so I can have access to the DefaultDisplay so I can have the device screen related information.

    Doing this IWindowManager windowManager = (IWindowManager)ApplicationContext.GetSystemService(Context.WindowService); will return null.

    Thank you.

    Thursday, August 22, 2013 7:59 AM

Answers

All replies

  • User401 posted

    Hi,

    this should work

      IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
    

    according to that post mono-for-android.1047100.n5.nabble.com/IWindowManager-td4845524.html

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, August 22, 2013 1:01 PM
  • User19848 posted

    Worked like a charm!

    Thank you.

    Thursday, August 22, 2013 1:21 PM
  • User2029 posted

    ty, starting with version 4.20.0.28 this probem reappeared.

    Monday, November 24, 2014 7:43 PM
  • User82076 posted

    It seems that JavaCast does not exists....

    Thursday, January 8, 2015 2:21 AM
  • User12460 posted

    Add the following using statement. That will import the Extension method JavaCast<T>

    using Android.Runtime;

    Wednesday, April 8, 2015 9:12 PM
  • User1071 posted

    This did my day Yey :smiley:

    Saturday, August 8, 2015 9:34 AM
  • User222192 posted

    The name 'Context' doesnot exist in the current context ? What does this mean and how can I remove this is there any idea ?

    Friday, May 6, 2016 2:03 AM
  • User200230 posted

    using Android.Content

    Wednesday, November 30, 2016 4:14 PM
  • User298773 posted

    With --> IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast();

    I have the error "An object reference is required for the non-static field, method, or propery 'Context.GetSystemService(string)'".

    Friday, February 10, 2017 6:57 PM
  • User334768 posted

    What worked for me is

    IWindowManager windowManager = Application.Context.GetSystemService(Context.WindowService).JavaCast();

    Friday, July 7, 2017 2:08 PM