C# 如何创建最小化的持续通知,如USB连接或谷歌天气
我正在开发一个Xamarin.Android应用程序,它使用前台服务跟踪用户在特定时间/距离后的位置 为了保持服务运行,我有一个低优先级的持续通知以及低优先级的通知通道。我尝试过各种组合(低优先级和最小优先级以及内容文本) 通知频道代码:C# 如何创建最小化的持续通知,如USB连接或谷歌天气,c#,android,xamarin.android,android-notifications,C#,Android,Xamarin.android,Android Notifications,我正在开发一个Xamarin.Android应用程序,它使用前台服务跟踪用户在特定时间/距离后的位置 为了保持服务运行,我有一个低优先级的持续通知以及低优先级的通知通道。我尝试过各种组合(低优先级和最小优先级以及内容文本) 通知频道代码: private NotificationChannel CreateNotificationChannel(string channelId) { if (Build.VERSION.SdkInt < BuildVersionCodes.O)
private NotificationChannel CreateNotificationChannel(string channelId)
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
return null;
}
string channelName = Resources.GetString(Resource.String.notification_channel_name);
string channelDesc = Resources.GetString(Resource.String.notification_channel_desc);
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationImportance.Default)
{
Description = channelDesc
};
switch(channelId)
{
case UPDATES_NOTIFICATION_CHANNEL_ID:
notificationChannel.Importance = NotificationImportance.High;
break;
case ONGOING_NOTIFICATION_CHANNEL_ID:
notificationChannel.Importance = NotificationImportance.Low;
break;
default:
break;
}
var notifManager = (NotificationManager)GetSystemService(NotificationService);
notifManager.CreateNotificationChannel(notificationChannel);
return notificationChannel;
}
private NotificationChannel CreateNotificationChannel(字符串channelId)
{
if(Build.VERSION.SdkInt
通知代码:
private Notification CreateOngoingNotification()
{
Intent notificationIntent = new Intent(this, typeof(MainActivity));
PendingIntent pendingIntent =
PendingIntent.GetActivity(this, 0, notificationIntent, 0);
string content = "The application is fetching your location every " + MIN_TIME / (60 * 1000) + " minutes if you moved at least " + MIN_DISTANCE + " meters.";
NotificationCompat.Builder builder;
if (Build.VERSION.SdkInt < BuildVersionCodes.O) builder = new NotificationCompat.Builder(this);
else builder = new NotificationCompat.Builder(this, m_ongoingNotificationChannel.Id);
builder
.SetContentTitle("Persistent notification")
.SetStyle(new NotificationCompat.BigTextStyle().BigText(content))
.SetSmallIcon(Resource.Drawable.ic_notification)
.SetContentIntent(pendingIntent)
.SetGroup("persistent")
.SetOngoing(true)
.SetVisibility((int)NotificationVisibility.Private)
.SetPriority((int)NotificationPriority.Low);
Notification notification = builder.Build();
return notification;
}
私有通知createOnGoInNotification()
{
意向通知意向=新意向(此,类型为(主活动));
下垂的,下垂的=
PendingEvent.GetActivity(this,0,notificationIntent,0);
string content=“如果您至少移动了“+MIN\u距离+”米,则应用程序每隔“+MIN\u时间/(60*1000)+”分钟获取您的位置。”;
通知建筑商;
如果(Build.VERSION.SdkInt
记住下面的图片,我想要完成的是LinkedIn应用程序、Google Weather应用程序(底部)和另一个应用程序(从末尾开始的第三个应用程序)的通知样式
我能得到的只是标题中有“持久通知”的那个
欢迎任何形式的帮助
编辑:明确说明我使用的是Xamarin,而不是Java,如果我没有错,并且您正在寻找 基本通知通常包括标题、一行文本以及用户可以执行的一个或多个响应操作。为了提供更多信息,您还可以通过应用多个通知模板之一来创建大型、可扩展的通知 现在,如果您仔细阅读文档,它有所有不同类型的可扩展通知 您正在寻找的是
添加一大块文本
或创建收件箱样式的通知
文档中提供的两种代码都可以轻松转换为C#,即Xamarin.Android
如果您遇到问题或有疑问,请随时回复
Goodluck当你长按并向下滚动它时,它应该会打开,你到底想要什么?我明天会查看它。但我已经在使用可扩展通知(标题为KeepTraveling的通知)。问题是它没有像其他应用程序的通知那样最小化。无论如何,我会研究这些可扩展的,我可能会错过一些东西。当然你可以这样做,让我知道我是否可以帮助你,或者其他我已经尝试了这两种类型,但仍然得到相同的布局。我是否需要创建自定义布局而不是通知类型?我不确定是否有方法在此处添加自定义布局!你能在问题中添加你到底想要实现什么的图片吗?好吧,也许我没有解释我自己,问题中添加的图片显示了我的实际通知(KeepTraveling)和我想要实现的内容(最下面的:Google Weather、LinkedIn和另一个是usb连接选项)。