Search code examples
androiduno-platform

How to get Android.Content.Context object in Android head


I'm working on integrating an java binding project, and I need to pass an Android.Content.Context object to the method, how do I get that in Uno?


Solution

  • To get the current Android Context within an Uno app you can use the Uno.UI.ContextHelper.Current property.

    Simple example:

    #if __ANDROID__
        public partial class CustomNativeScrollView : Android.Widget.ScrollView
        {
            public CustomNativeScrollView() : base(Uno.UI.ContextHelper.Current)
            {
    
            }
    
        ...