C# 如何使用GoogleAppAvailability?当我想使用它时,我总是收到一条错误消息

C# 如何使用GoogleAppAvailability?当我想使用它时,我总是收到一条错误消息,c#,xamarin.android,C#,Xamarin.android,我在此行中收到一条错误消息: int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); 错误CS0103:名称“GoogleAppAvailability”在当前上下文中不存在 怎么了?我遵循了本教程,但仍然收到错误消息。 活动1.cs: using Android.App; using Android.Content.PM; using Android.OS; using And

我在此行中收到一条错误消息:

int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
错误CS0103:名称“GoogleAppAvailability”在当前上下文中不存在

怎么了?我遵循了本教程,但仍然收到错误消息。

活动1.cs:

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Android.Content;
using Android.Gms.Common;
using Firebase.Messaging;
using Firebase.Iid;
using Android.Util;

namespace ggdgdgd.Android
{
[Activity(Label = "ggdgdgd.Android"
    , MainLauncher = true
    , Icon = "@drawable/ic_launcher"
    , Theme = "@style/Theme.Splash"
    , AlwaysRetainTaskState = true
    , LaunchMode = LaunchMode.SingleInstance
    , ScreenOrientation = ScreenOrientation.FullUser
    , ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
public class Activity1 : Microsoft.Xna.Framework.AndroidGameActivity
{
    static readonly string TAG = "MainActivity";
    internal static readonly string CHANNEL_ID = "my_notification_channel";
    internal static readonly int NOTIFICATION_ID = 100;

    string Texttest = "";

    public bool IsPlayServicesAvailable()
    {
        int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.Success)
        {
            if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
                Texttest = GoogleApiAvailability.Instance.GetErrorString(resultCode);
            else
            {
                Texttest = "This device is not supported";
                Finish();
            }
            return false;
        }
        else
        {
            Texttest = "Google Play Services is available.";
            return true;
        }
    }

    void CreateNotificationChannel()
    {
        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            // Notification channels are new in API 26 (and not a part of the
            // support library). There is no need to create a notification
            // channel on older versions of Android.
            return;
        }

        var channel = new NotificationChannel(CHANNEL_ID,
                                              "FCM Notifications",
                                              NotificationImportance.Default)
        {

            Description = "Firebase Cloud Messages appear in this channel"
        };

        var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
        notificationManager.CreateNotificationChannel(channel);
    }

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        Xamarin.Essentials.Platform.Init(this, bundle);
        Xamarin.Forms.Forms.Init(this, bundle);
        Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

        if (Intent.Extras != null)
        {
            foreach (var key in Intent.Extras.KeySet())
            {
                var value = Intent.Extras.GetString(key);
                Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
            }
        }

        var g = new Game1();
        SetContentView((View)g.Services.GetService(typeof(View)));
        IsPlayServicesAvailable();
        CreateNotificationChannel();        
        g.Run();
    }


    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
    }
}
}
使用Android.App;
使用Android.Content.PM;
使用Android.OS;
使用Android.Views;
使用Android.Content;
使用Android.Gms.Common;
使用Firebase.Messaging;
使用Firebase.Iid;
使用Android.Util;
名称空间ggdgdgd.Android
{
[活动(Label=“ggdgdgd.Android”
,MainLauncher=true
,Icon=“@drawable/ic_启动器”
,Theme=“@style/Theme.Splash”
,AlwaysRetainTaskState=true
,LaunchMode=LaunchMode.SingleInstance
,ScreenOrientation=ScreenOrientation.FullUser
,ConfigurationChanges=ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]
公共类活动1:Microsoft.Xna.Framework.AndroidGameActivity
{
静态只读字符串TAG=“MainActivity”;
内部静态只读字符串通道\u ID=“我的通知\u通道”;
内部静态只读int通知\u ID=100;
字符串Texttest=“”;
公共bool isplayservicesavaailable()
{
int-resultCode=GooglePayAvailability.Instance.IsGooglePlayServicesAvailable(此);
if(resultCode!=ConnectionResult.Success)
{
if(GoogleAppAvailability.Instance.IsUserResolvableError(resultCode))
Texttest=GoogleAppAvailability.Instance.GetErrorString(resultCode);
其他的
{
Texttest=“不支持此设备”;
完成();
}
返回false;
}
其他的
{
text测试=“谷歌播放服务可用。”;
返回true;
}
}
void CreateNotificationChannel()
{
if(Build.VERSION.SdkInt
您确定有最新的NuGet和SDK可用吗

GoogleAppAvailability
Android.Gms.Common
命名空间的一部分,通常随SDK一起提供,要么您没有安装正确的Xamarin/Android SDK,要么您的SDK非常旧

也可能是一些编译器错误,可以通过重新启动来解决