本周我通过几个绑定库将 IntercomIO SDK 添加到了我们的 Xamarin.Forms 应用程序中,我目前正在尝试让推送通知工作,但在 MainActivity 中调用 PushHandlerService.Register(this) 后不久,应用程序崩溃说它找不到类 com.google.android.gms.gcm.GcmReceiver 甚至没有被这个调用周围的 try catch 块捕获。
这是 MainActivity 中负责在 Android 上设置推送通知的方法。
public void registerForPushNotifications()
{
try
{
GcmClient.CheckDevice(this);
GcmClient.CheckManifest(this);
//Register the app for push notifications.
PushHandlerService.Initialize(this);
//if (!GcmClient.IsRegistered(this))//Temporarily force the app to register for push notifications
{
System.Diagnostics.Debug.WriteLine("Registering");
// Register for GCM
PushHandlerService.Register(this);
}
LocalBroadcastManager lbc = LocalBroadcastManager.GetInstance(this);
PushActionReceiver rec = new PushActionReceiver(this);
lbc.RegisterReceiver(rec, new IntentFilter("pushaction"));
}
catch (Java.Net.MalformedURLException)
{
var e = new Exception("There was an error creating the Mobile Service. Verify the URL");
System.Diagnostics.Debug.Fail(String.Format(@"Exception at {0}: {1}", this.GetType().Name, e.Message));
Insights.Report(e);
}
catch (Exception e)
{
System.Diagnostics.Debug.Fail(String.Format(@"Exception at {0}: {1}", this.GetType().Name, e.Message));
if (e.GetType() != typeof(TaskCanceledException))
Insights.Report(e);
}
}
在清单中,我添加了对讲机的接收器定义
<receiver android:name="io.intercom.android.sdk.gcm.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"></receiver>
当我不调用 PushHandlerService.Register(this) 时,问题不会发生,但显然我无法再收到任何推送通知(包括来自我们自己系统的推送通知)
这里发生了什么?我正确设置了库和依赖项,但似乎无法找到 GcmReceiver 类..