So I am trying to register my application with GCM using the Google Cloud Messaging Client component in Xamarin.
when ever I run this code in my application, however, it gets a runtime error at the GcmClient.CheckDevice(this) method call. The button is in the main activity and its just so I have control of when I start the registration process.
I am using the Xamarin player emulator to load the app.
button.Click += (object sender, EventArgs e) =>
{
GcmClient.CheckDevice(this);
GcmClient.CheckManifest(this);
var preferences = GetSharedPreferences("AppData", FileCreationMode.Private);
var deviceid = preferences.GetString("DeviceId", "");
if (string.IsNullOrEmpty(deviceid))
{
Toast.MakeText(this, "I'm here", ToastLength.Short).Show();
GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS);
}
};
Any aid would be greatly appriciated. Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="my_package_name">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
<application android:label="patientFlowNotifications"></application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
The Xamarin Player Emulator doesn't ships with Google Play Services by default. You need to manually install them in order to use GCM:
http://developer.xamarin.com/guides/android/getting_started/installation/android-player/
Another point that will not inevitably cause an exception but will prevent your app from running as expected is that you have not declared any intent filters in your manifest and a app-specific CDM-Permission is missing.