错误Java.exe用代码1 Xamarin Firbase消息传递

发布于 2025-02-06 09:09:35 字数 2360 浏览 2 评论 0 原文

我正在使用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”})] 代码正确编译了

I am using nuget package Xamarin.Firebase.Messaging and Xamarin.GooglePlayServices.Baseto receive push notifications in my app, previously it was working fine, but when I update visual studio 2022 to 17.2.3 it stopped working

I Tried all of these:

  • Update all nuget packages
  • delete obj bin folder from all shared projects
  • enable multidex
  • install and include

<PackageReference Include="Xamarin.Google.Guava" ExcludeAssets="all"> <Version>27.1.0</Version> </PackageReference>

and nothing i did before has worked

my code to receive push notifications:

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

if I remove [Service] or
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })] the code compiles correctly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫儰鉨ミ守葔 2025-02-13 09:09:38

显然,这是由于我对Visual Studio的更新造成的,因为Android SDK也已更新,该解决方案是编辑 [services] [services(exported = true)] 对于Android +31,留下这样的最终代码。

[Service(Exported = true)]
[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);
    }
}

添加之后,所有内容都正确编译了

字体答案

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.

[Service(Exported = true)]
[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);
    }
}

After adding that, everything compiled correctly

font answer

平生欢 2025-02-13 09:09:38

除了这里的答案外,我还必须导出广播的响应者

[BroadcastReceiver(Enabled = true, Exported = true)]

In addition to the answers here, I also had to export the broadcast reviver

[BroadcastReceiver(Enabled = true, Exported = true)]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文