【问题标题】:Hidden Notification in StartForeground in xamarin form以 xamarin 形式在 StartForeground 中隐藏通知
【发布时间】:2021-11-18 05:39:42
【问题描述】:

当服务在后台运行时,我可以隐藏通知“应用程序名称正在运行”吗?

我的通知是:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
   .SetDefaults((int)NotificationDefaults.All)
   .SetSmallIcon(Resource.Drawable.navigation_empty_icon)
   .SetVibrate(new long[] { 100, 200, 300, 400, 500, 400, 300, 200, 400 })
   .SetSound(null)
   .SetChannelId(channelId)
   .SetPriority(NotificationCompat.PriorityMin)
   .SetAutoCancel(true)
   .SetContentTitle("")
   .SetContentText("")
   .SetNotificationSilent()
   .SetOngoing(false);
 
StartForeground(1, builder.Build());

【问题讨论】:

  • 隐藏通知是什么意思?如果您希望不弹出通知,可以在 API 级别 26 以下时更改优先级。从 API 级别 26 或以上开始,您需要设置通道优先级。
  • 这意味着如何在没有通知的情况下运行 StartForeground?

标签: c# xamarin xamarin.forms xamarin.android background-service


【解决方案1】:

这意味着如何在没有通知的情况下运行 StartForeground?

我们无法在没有通知的情况下运行 StartForeground。通知是强制性的。

StartForeground 有两个参数,都是强制的:

  • 一个整数值,在应用程序中唯一可识别
    服务。
  • Android 将在
    中显示的 Notification 对象 只要服务正在运行,状态栏就会一直显示。

有关详细信息,请查看 MS 文档。 https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services

【讨论】:

  • 那么如何在不通知的情况下在后台运行程序????
  • 我们总是使用服务来做后台工作。你是怎么做baclground工作的?通知在你的背景中是什么样的?
  • 当我的服务运行时显示通知 "App name is running" 。我不想显示这个。还有没有其他方法可以在没有服务的情况下在后台运行应用程序?
猜你喜欢
  • 1970-01-01
  • 2021-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-21
  • 1970-01-01
  • 2020-04-12
相关资源
最近更新 更多