如何解决更新 Xamarin.Android 上的通知文本
public void StartAppService()
{
...
using (var intent = new Intent(Application.Context,typeof(RunningAppService)))
{
Application.Context.StartForegroundService(intent);
}
}
private const int ServiceRunningNotificationId = 10000;
public override StartCommandResult OnStartCommand(Intent intent,StartCommandFlags flags,int startId)
{
CreateNotificationChannel();
using (var notification = new Notification.Builder(this,"10111")
.SetContentTitle("Artemis HZ")
.SetContentText("90 HZ")
.SetSmallIcon(Resource.Drawable.icon)
.Setongoing(true)
.Build())
{
StartForeground(ServiceRunningNotificationId,notification);
}
...
return StartCommandResult.Sticky;
}
private void CreateNotificationChannel()
{
const string channelName = "TopAppServiceChannel";
const string channelDescription = "TopAppServiceChannel";
using (var channel = new NotificationChannel("10111",channelName,NotificationImportance.Default)
{
Description = channelDescription
})
{
using (var notificationmanager = (notificationmanager)GetSystemService(NotificationService))
{
notificationmanager?.CreateNotificationChannel(channel);
}
}
}
我想以编程方式更改它的 SetContentText。 我试着这样做:
using (var notificationBuilder = new Notification.Builder(this,"10111")
.SetContentText($"{(int)hz} HZ"))
{
using (var notificationmanager = (notificationmanager)GetSystemService(NotificationService))
{
notificationmanager?.Notify(10111,notificationBuilder.Build());
}
}
然后什么也没有发生。它只在应用启动的前几秒有效,但之后它就保持原样,不会再次改变。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。