如何创建像USB连接或谷歌的天气持续最小化的通知

问题描述 投票:0回答:1

我开发使用前景一定的服务时间/距离后,跟踪用户的位置Xamarin.Android应用。

为了保持业务正常运行我有一个低优先级的持续通知以及与低优先级也通知信道。我已经尝试了所有类型的组合(低优先级最小和内容文本)的。

NotificationChannel代码:

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 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;
}

铭记下面的图片,我尝试以acomplish是从LinkedIn应用程序的通知的风格,谷歌天气一(底部),而另一个(第三一名来自年底开始)。

我能得到的是一个在标题为“永久通知”。

任何形式的帮助将受到欢迎!

编辑:明确表示,我使用Xamarin,而不是Java

c# android xamarin.android android-notifications
1个回答
0
投票

如果我没看错,你正在寻找一个expandable notification

一个基本的通知通常包括标题,文本的行,和一个或多个动作的用户可以响应执行。为了提供更多的信息,您还可以通过应用的若干通知模板创建一个大的,可扩展的通知。

现在,如果你阅读文档仔细它有各种不同类型的可扩展的通知,

你正在寻找的一个或者是Add a large block of textCreate an inbox-style notification

文档上可用的两个代码易于转换到C#即Xamarin.Android

如果遇到问题或有疑问随时恢复

祝好运

© www.soinside.com 2019 - 2024. All rights reserved.