Check if Google Play Services are availble in Xamarin

This is actually pretty easy. Make sure you have Xamarin.GooglePlayServices.Gcm installed in your project.  Then use the following code:


using System;
using Android.Content;
using Android.Gms.Common;
public static class GoogleServices
{
private static Context _context;
public static void Init(Context context)
{
_context = context;
}
public static bool IsGoogleServicesAvailable()
{
Ensure.Condition(_context != null, () => { throw new Exception("Make sure you have called GoogleServices.Init in MainActivity"); });
var resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(_context);
return resultCode == ConnectionResult.Success;
}
}

Remember to call GoogleServices.Init(this) in your MainActivity after Forms.Init(this, bundle).

Comments