本周,我通过一对夫妻绑定库向我们的Xamarin.Forms应用程序添加了IntercomIO SDK,目前我试图让推送通知工作,但不久后我在MainActivity中调用PushHandlerService.Register(this)时,应用程序崩溃,说它无法找到com.google.android.gms.gcm.GcmReceiver类,该类甚至没有被围绕此调用的try catch块捕获。无法注册Xamarin Android上的推送通知以及IntercomIO
以下是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(本)的问题不会发生,但是那显然我不能再次收到推送通知(包括我们自己系统的推送通知)
这是怎么回事?我已经正确设置了库和依赖项,但似乎无法找到GcmReceiver类。
)它开始按预期工作。 – zezioen