以下代碼爲GCM獲取令牌...給出例外。instanceID.GetToken()給出異常
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;
}
}
異常
java.io.IOException的:在SERVICE_NOT_AVAILABLE System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c]
全部異常
{Java.IO.IOException:SERVICE_NO T_AVAILABLE at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] /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]:0在 LeaveApplication.Droid.RegistrationIntentService.OnHandleIntent (Android.Content.Intent intent)[0x0003a] D:\ Workspaces \ temp \ LeaveApplication \ LeaveApplication \ LeaveApplication \ LeaveApplication.Droid \ RegistrationIntentService.cs:36 ---管理的異常堆棧跟蹤結束--- 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(來源不明)處 md54d5d90974a2844b8ac95dbb0c513d773.RegistrationIntentService.n_onHandleIntent(本地 法) com.google.android.gms.iid.InstanceID.getToken(來源不明)在 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 )在 android.os.HandlerThread.run(HandlerThread.java:61)}
我的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>
這是我的錯誤,互聯網不在設備上工作,這是我從我的組織。 –