Following code for GCM get token...gives exception.
protected override void OnHandleIntent(Intent intent)
{
try
{
Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken");
lock (locker)
{
var instanceID = InstanceID.GetInstance(Application.Context);
var token = instanceID.GetToken(
"<Project number>", GoogleCloudMessaging.InstanceIdScope, null);// exception occurred at this line
Log.Info("RegistrationIntentService", "GCM Registration Token: " + token);
SendRegistrationToAppServer(token);
Subscribe(token);
}
}
catch (Exception e)
{
Log.Debug("RegistrationIntentService", "Failed to get a registration token");
return;
}
}
Exception
Java.IO.IOException: SERVICE_NOT_AVAILABLE at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c]
Full Exception
{Java.IO.IOException: SERVICE_NOT_AVAILABLE at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00064] in /Users/builder/data/lanes/3053/a94a03b5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195 at Android.Gms.Gcm.Iid.InstanceID.GetToken (System.String authorizedEntity, System.String scope, Android.OS.Bundle extras) [0x00096] in :0 at LeaveApplication.Droid.RegistrationIntentService.OnHandleIntent (Android.Content.Intent intent) [0x0003a] in D:\Workspaces\temp\LeaveApplication\LeaveApplication\LeaveApplication\LeaveApplication.Droid\RegistrationIntentService.cs:36 --- End of managed exception stack trace --- java.io.IOException: SERVICE_NOT_AVAILABLE at com.google.android.gms.iid.zzc.zzb(Unknown Source) at com.google.android.gms.iid.zzc.zza(Unknown Source) at com.google.android.gms.iid.InstanceID.zzc(Unknown Source) at com.google.android.gms.iid.InstanceID.getToken(Unknown Source) at md54d5d90974a2844b8ac95dbb0c513d773.RegistrationIntentService.n_onHandleIntent(Native Method) at md54d5d90974a2844b8ac95dbb0c513d773.RegistrationIntentService.onHandleIntent(RegistrationIntentService.java:36) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61) }
my android manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourcompany.LeaveApplication" android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15" />
<application android:label="XamarinLeaveApp"></application>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.yourcompany.LeaveApplication.permission.C2D_MESSAGE" />
<permission android:name="com.yourcompany.LeaveApplication.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<receiver android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.yourcompany.LeaveApplication" />
</intent-filter>
</receiver>
</manifest>