[英]OnMessageReceived is not invoked
I am trying to get to work with xamarin notifications. 我正在尝试使用xamarin通知。 For android I have followed these steps: https://developers.google.com/cloud-messaging/android/client for the client side to show the notification. 对于android,我已按照以下步骤操作: https : //developers.google.com/cloud-messaging/android/client用于客户端以显示通知。 On my server side I am using pushSharp plugin and everything is looks to work fine since the message from the server side is sent. 在我的服务器端,我使用的是pushSharp插件,由于发送了服务器端的消息,因此一切看起来都可以正常工作。 The problem is that I don't get the notification on my phone. 问题是我没有在手机上收到通知。 My app just crushes when I'm in debug mode or sometimes times it crushes when the app is in background too. 我的应用只是在调试模式下崩溃,有时甚至在后台运行时也会崩溃。 As I can see this method : 如我所见,此方法:
public override void OnMessageReceived(string from, Bundle data){//Extract the message received from GCM:
var message = data.GetString("message");
Log.Debug("MyGcmListenerService", "From: " + from);
Log.Debug("MyGcmListenerService", "Message: " + message);
//Forward the received message in a local notification:
SendNotification(message);}
it's not called at all. 根本没有被调用。 My manifest is as followed : 我的清单如下:
<service android:name="com.my_companyname_goes_here.app_name_goes_here.android.MyGcmListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
I tried searching the web for an answer but none as followed solved my problem : GcmListenerService is not called When Application is in Background Xamarin GCM OnMessageReceived is not called ect etc. Any kind of help would be appreciated. 我尝试在Web上搜索答案,但没有一个解决了我的问题: 当应用程序在后台 Xamarin中 时,未调用GcmListenerService。GCM OnMessageReceived 未调用 ect等。将提供任何帮助。
Edit : This is my json 编辑:这是我的json
{
"message": "test",
"vibrate": 1,
"sound": 1
}
You could read the Xamarin official document Xamarin Google Cloud Messaging : 您可以阅读Xamarin官方文档Xamarin Google Cloud Messaging :
https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/ https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/
Here is the sample about the above document : 这是有关上述文档的示例:
https://developer.xamarin.com/samples/monodroid/RemoteNotifications/ https://developer.xamarin.com/samples/monodroid/RemoteNotifications/
Also, please make sure Google Play Services is available in your device. 另外,请确保您的设备上可以使用Google Play服务 。
Please try to add the service attribute like this : 请尝试添加服务属性,如下所示:
[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
public class MyGcmListenerService : GcmListenerService
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.