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:
Remember to call GoogleServices.Init(this) in your MainActivity after Forms.Init(this, bundle).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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