0

我在C#Xamarin.Android項目上實施了推送通知,就像他們在官方Firebase文檔中一樣。RuntimeException在收到通知後拋出

可以使用Firebase控制檯發送通知。現在我試圖從另一個C#服務發送消息。設備監視器說,GCM消息已發送。

見Android設備監視郵件:http://imgur.com/a/wNOV3

這裏是我的代碼。爲何會發生這種情況?

AndroidManifest.xml中

<application android:label="myApp" android:icon="@drawable/icon"> 
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> 
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> 
    <intent-filter> 
    <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
    <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
    <category android:name="${applicationId}" /> 
    </intent-filter> 
    </receiver> 

<service android:name=".MyFirebaseMessagingService"> 
    <intent-filter> 
     <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
    </intent-filter> 
</service> 
</application> 

MyFirebaseMessagingService.cs

[Service] 
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] 
public class MyFirebaseMessagingService : FirebaseMessagingService 
{ 
    const string TAG = "MyFirebaseMsgService"; 

    public MyFirebaseMessagingService() 
    { 
     Log.Debug(TAG, "Service called"); 
    } 
    public override void OnMessageReceived(RemoteMessage message) 
    { 
     string msg = message.GetNotification().Body; 
     Log.Debug(TAG, msg);  
    } 
} 

回答

0

我得到了它這個清單配置

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxx.xxxx" android:versionName="1.0.0" android:versionCode="2"> 
    <uses-sdk android:minSdkVersion="15" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <application android:icon="@drawable/icon" android:label="XX xXx"> 
     <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" /> 
     <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
       <category android:name="${applicationId}" /> 
      </intent-filter> 
     </receiver> 
    </application> 
</manifest> 
+0

我在MyApp.Droid.MyFirebaseMessagingService得到一個AndroidRuntime錯誤工作。 OnMessageReceived與此配置 – localhorst27

+0

你可以發佈你的日誌? – Leze

+0

現在有效。但是,如果應用程序是開放的,那麼沒有通知。如果該應用已關閉,則可以使用。 – localhorst27