本週,我通過一對夫妻綁定庫向我們的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