错误Java.exe用代码1 Xamarin Firbase消息传递
我正在使用nuget package xamarin.firebase.messaging
和 xamarin.googleplayplayservices.base
以接收我的应用程序中的推送通知,但当我更新 Visual Studio 2022至17.2.3
它停止工作,
我尝试了所有这些:
- 更新所有Nuget软件包
- 从所有共享项目中删除OBJ BIN文件夹
- 启用Multidex
- install,并包括
< packageReference include =“ xamarin.google.google.google.google.google 。 <版本> 27.1.0</version> </packageReference>
i i i i i i i i i i i i>以前做过
我的代码以接收推送通知:
using System;
using System.Threading.Tasks;
using Android.App;
using Firebase.Messaging;
using Plugin.DeviceInfo;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace MyApp.Droid
{
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
readonly AndroidNotificationManager _androidNotification = new AndroidNotificationManager();
public override void OnMessageReceived(RemoteMessage message)
{
var mensajeData = message.Data;
string title= mensajeData["notiTitle"];
string bodymessage= mensajeData["notiBody"];
_androidNotification.CreateLocalNotification(title, bodymessage);
}
public override void OnNewToken(string token)
{
base.OnNewToken(token);
Preferences.Set("TokenFirebase", token);
}
}
}
如果我删除 [服务]
或
[IntentFilter(new [] {“ com.google.firebase.messaging_event”})]
代码正确编译了
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,这是由于我对Visual Studio的更新造成的,因为Android SDK也已更新,该解决方案是编辑
[services]
[services(exported = true)]
对于Android +31,留下这样的最终代码。添加之后,所有内容都正确编译了
字体答案
Apparently it was due to the update I made of visual studio because the android SDK was also updated, the solution was to edit
[Services]
to[Services(Exported = true)]
for android +31, leaving the final code like this.After adding that, everything compiled correctly
font answer
除了这里的答案外,我还必须导出广播的响应者
In addition to the answers here, I also had to export the broadcast reviver