UI层如何访问GetSystemService(AudioService)

How to access GetSystemService(AudioService) in the UI layer

我正在 Xamarin 中开发 android 应用程序。我想在 UI 层中创建一个接口及其实现 class 。正如您在下面的代码中看到的, 我总是出错,我使用

this.GetSystemService(AudioService);

它永远不会被识别。 请看看下面的导入。请让我知道如何让它工作。

代码:

 public class ImplClass :   
 InterfaceFile
 {
    public bool IsAllowed(Context ctx)
    {
        AudioManager audioMgr = 
 (AudioManager)this.GetSystemService(AudioService);
     }
    }

进口:

using System;
using System.Runtime.Remoting.Contexts;
using Android.Media;
using MvvmCross.Platform;
using Android.Content.PM;

您可以使用 "Application Context".

示例:

public class ImplClass : InterfaceFile
{
    public bool IsAllowed(Context ctx)
    {
        AudioManager audioMgr = (AudioManager)Application.Context.GetSystemService(AudioService);
    }
}

我正在使用这个并且它有效。

global::Android.App.Application.Context.GetSystemService