Interface in .NET MAUI

Anonymous
2023-02-05T20:43:34.63+00:00

Hi,

How can Implement Interface in .NET MAUI?

I want to implement the below to access the App's Settings for both iOS and Android.

Screenshot 2023-02-06 at 12.43.20 AM

Thanks,

Jassim

Developer technologies | .NET | .NET MAUI
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-02-06T03:42:54.2166667+00:00

    Hello,

    You can use Conditional compilation, do not need to create interface and invoke platform code.

    You can run this iOS and Android platform code directly with conditional compilation in the MAUI. For example, I execute this code in the button click event like following code.

    
    private async void OnCounterClicked(object sender, EventArgs e)
        {
    #if ANDROID
            var intent=new Android.Content.Intent(Android.Provider.Settings.ActionApplicationSettings);
            intent.AddFlags(Android.Content.ActivityFlags.NewTask);
            var uri=  Android.Net.Uri.FromParts("package", package_name,null);
            intent.SetData(uri);        
    #elif IOS
               var url = new Foundation.NSUrl($"app-settings:{app_bundle_id}");
            UIKit.UIApplication.SharedApplication.OpenUrl(url);
    #endif    }
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.