Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to sort notifications by id ? #376

Open
andrei-cb opened this issue Feb 24, 2023 · 3 comments
Open

How to sort notifications by id ? #376

andrei-cb opened this issue Feb 24, 2023 · 3 comments
Labels
Android Android only issue enhancement New feature or request

Comments

@andrei-cb
Copy link

Can't find any option to do this but looks like it is possible in Android.

https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setSortKey(java.lang.String)

@andrei-cb
Copy link
Author

I did try to add builder.SetSortKey(request.NotificationId.ToString()); in NotificationServiceImpl.cs but it's still not sorting them by notification id.

@thudugala
Copy link
Owner

Set a sort key that orders this notification among other notifications from the same package. This can be useful if an external sort was already applied and an app would like to preserve this. Notifications will be sorted lexicographically using this value, although providing different priorities in addition to providing sort key may cause this value to be ignored.

@thudugala thudugala added enhancement New feature or request Android Android only issue labels Mar 4, 2023
@andrei-cb
Copy link
Author

Hi, I am setting the same priority for all notifications, but they still don't get sorted.

Channel:

android.AddChannel(new NotificationChannelRequest
{
	Id = $"my_channel_01",
	Name = "Channel 1",
	Description = "blablabla",
	Importance = AndroidImportance.Low

});

Summary:

var notification = new NotificationRequest
{
        NotificationId = 1,
        Title = "appName",
        ReturningData = "none",
        Group = "appName",
        Android =
        {
	        IsGroupSummary = true,
	        ChannelId = "my_channel_01",
	        Ongoing = false,
	        AutoCancel = false,
	        Priority =  AndroidPriority.Low
        }
};

Notifications:

var notification = new NotificationRequest
{
        NotificationId = getNotificationId(defaultPriority),
        Title = "appName",
        Subtitle = priorityNames[defaultPriority],
        Description = notiText,
        Group = "appName",
        Android =
        {
                IconSmallName =
                {
	                ResourceName = priorityIcons[defaultPriority]
                },
                IconLargeName =
                {
	                ResourceName = priorityIcons[defaultPriority]
                },
                IsGroupSummary = false,
                Ongoing = persistentNotification,
                ChannelId = "my_channel_01",
                AutoCancel = false,
                Priority =  AndroidPriority.Low
        }
};

image

getNotificationId returns a number based on priority (high = 10000, medium = 20000, low = 30000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android only issue enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants