【发布时间】:2022-08-20 13:48:15
【问题描述】:
我正在尝试设置Xamarin.Firebase.Messaging,它说要指定android:exported,我尝试添加一些活动标签,我也发现了很多类似的问题,但在我的 .NET MAUI 项目中没有任何工作,或者我只是不知道如何请参阅MyFirebaseMessagingService.cs。
它引发了这个错误:
Severity Code Description Project File Line Suppression State
Error AMM0000
android:exported needs to be explicitly specified for element <service#crc64bdb245ab40403d31.MyFirebaseMessagingService>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
FIrebasePushNotoficationsTest2 C:\\Users\\Lukas-PC\\source\\repos\\FIrebasePushNotoficationsTest2\\FIrebasePushNotoficationsTest2\\obj\\Debug\\net6.0-android31.0\\AndroidManifest.xml 28
当我从MyFirebaseMessagingService.cs 中删除[Service] 时,通知工作有效,但不调用方法OnMessageReceived。
MyFirebaseMessagingService.cs:
using Android.App;
using Firebase.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FIrebasePushNotoficationsTest2.Platforms.Android
{
[Service]
[IntentFilter(new[] { \"com.google.firebase.MESSAGING_EVENT\" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
public override void OnMessageReceived(RemoteMessage message)
{
Log.SendLog($\"Msg:{message.GetNotification().Body}\");
}
}
}
AndroidManifest.xml
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\">
<application android:allowBackup=\"true\" android:icon=\"@mipmap/appicon\" android:roundIcon=\"@mipmap/appicon_round\" android:supportsRtl=\"true\">
<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>
<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />
<uses-permission android:name=\"android.permission.INTERNET\" />
</manifest>
MainActivity.cs:
using Android.App;
using Android.Content.PM;
using Android.OS;
using Firebase.Iid;
using Firebase.Messaging;
namespace FIrebasePushNotoficationsTest2;
[Activity(Theme = \"@style/Maui.SplashTheme\", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
FirebaseMessaging.Instance.SubscribeToTopic(\"General\");
var t = FirebaseInstanceId.Instance.Token;
Log.SendLog($\"T:{t}\");
}
}
我的项目:
标签: android firebase xamarin firebase-cloud-messaging .net-maui