gpt4 book ai didi

android - 升级到最新的 android/firebase sdk,这个 azure 通知中心示例 - xamarin forms

转载 作者:行者123 更新时间:2023-12-02 07:38:29 31 4
gpt4 key购买 nike

我正在尝试升级到最新的 android/firebase sdk,此示例 https://github.com/xamcat/mobcat-samples/tree/master/notification_hub_backend_service

我面临一些已弃用的函数,并在下面的代码中遇到此异常

Java.Lang.NoSuchMethodException Message=getToken[]

非常清楚,但我不知道如何获取 token

 public void OnSuccess(Java.Lang.Object result)
{
DeviceInstallationService.Token = result.Class.GetMethod("getToken").Invoke(result).ToString();
}

编辑:MainActivity.cs

using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.CurrentActivity;
using Xamarin.Forms;
using AppCliente.Services.LogOn;
using Android.Content;
using Microsoft.Identity.Client;
using AppCliente.Services.NotificationHub;
using AppCliente.Droid.Services;
using Firebase.Iid;
using Firebase;
using Firebase.Installations;
using Firebase.Messaging;

namespace AppCliente.Droid
{
[Activity(Label = "AppCliente", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, Android.Gms.Tasks.IOnSuccessListener
{
IPushDemoNotificationActionService _notificationActionService;
IDeviceInstallationService _deviceInstallationService;

IPushDemoNotificationActionService NotificationActionService
=> _notificationActionService ??
(_notificationActionService =
ServiceContainer.Resolve<IPushDemoNotificationActionService>());

IDeviceInstallationService DeviceInstallationService
=> _deviceInstallationService ??
(_deviceInstallationService =
ServiceContainer.Resolve<IDeviceInstallationService>());
protected override void OnCreate(Bundle savedInstanceState)
{
CrossCurrentActivity.Current.Init(this, savedInstanceState);
DependencyService.Register<IParentWindowLocatorService, AndroidParentWindowLocatorService>();

TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);

Bootstrap.Begin(() => new DeviceInstallationService());

FirebaseApp.InitializeApp(this);
if (DeviceInstallationService.NotificationsSupported)
{
FirebaseInstallations.GetInstance(Firebase.FirebaseApp.Instance).GetId().AddOnSuccessListener(this);
}

Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init();
LoadApplication(new App());
ProcessNotificationActions(Intent);
App.UIParent = this;
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
}

protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
ProcessNotificationActions(intent);
}



public void OnSuccess(Java.Lang.Object result)
{
DeviceInstallationService.Token = result.Class.GetMethod("getToken").Invoke(result).ToString();
}
void ProcessNotificationActions(Intent intent)
{
try
{
if (intent?.HasExtra("action") == true)
{
var action = intent.GetStringExtra("action");

if (!string.IsNullOrEmpty(action))
NotificationActionService.TriggerAction(action);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
}
}

最佳答案

今天我遇到了同样的错误并修复了它

MainActivity.cs中更改此设置

public void OnSuccess(Java.Lang.Object result)
{
DeviceInstallationService.Token = result.Class.GetMethod("getToken").Invoke(result).ToString();
}

进入此

public void OnSuccess(Java.Lang.Object result)
{
DeviceInstallationService.Token = result.ToString();
}

Token 是使用 GetMethod("getToken") 从结果中获取的字符串,但情况似乎不再如此,并且 getToken 方法已被删除.

关于android - 升级到最新的 android/firebase sdk,这个 azure 通知中心示例 - xamarin forms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66573961/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com