【发布时间】:2020-12-27 00:01:53
【问题描述】:
目前我有一个注册通知的应用程序:
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());
}
}
然后什么也没有发生。它仅在应用程序启动的最初几秒钟内有效,但之后它会保持原样,不会再次更改。
【问题讨论】:
-
您想更改收到通知的文本或使用其他文本生成新的通知?
-
@Anand 我想更改文本而不生成任何新通知
标签: c# android xamarin xamarin.android android-notifications