簡體   English   中英

不調用OnMessageReceived

[英]OnMessageReceived is not invoked

我正在嘗試使用xamarin通知。 對於android,我已按照以下步驟操作: https : //developers.google.com/cloud-messaging/android/client用於客戶端以顯示通知。 在我的服務器端,我使用的是pushSharp插件,由於發送了服務器端的消息,因此一切看起來都可以正常工作。 問題是我沒有在手機上收到通知。 我的應用只是在調試模式下崩潰,有時甚至在后台運行時也會崩潰。 如我所見,此方法:

 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);}

根本沒有被調用。 我的清單如下:

<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>

我嘗試在Web上搜索答案,但沒有一個解決了我的問題: 當應用程序在后台 Xamarin中 時,未調用GcmListenerService。GCM OnMessageReceived 未調用 ect等。將提供任何幫助。

編輯:這是我的json

{
"message": "test",
"vibrate": 1,
"sound": 1
}

您可以閱讀Xamarin官方文檔Xamarin Google Cloud Messaging

https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-gcm/

這是有關上述文檔的示例:

https://developer.xamarin.com/samples/monodroid/RemoteNotifications/

另外,請確保您的設備上可以使用Google Play服務

更新:

請嘗試添加服務屬性,如下所示:

[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
public class MyGcmListenerService : GcmListenerService
{
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM