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

New Local Notification Sample port from Legacy #341

Merged
merged 18 commits into from
Dec 19, 2022

Conversation

officialgio
Copy link
Contributor

@officialgio officialgio commented Jul 12, 2022

Local Notification should allow the user to click on a button and the user should receive a notification of the times the button is clicked.

Copy link
Member

@tj-devel709 tj-devel709 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Start! Few suggestions and questions


void CreateNotificationChannel ()
{
ArgumentNullException.ThrowIfNull(Resources);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArgumentNullException.ThrowIfNull(Resources);
ArgumentNullException.ThrowIfNull (Resources);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

{
ArgumentNullException.ThrowIfNull(Resources);

// API 26 and below works but are new in API 26+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that you included a message here, but does not seem super clear to me.
Maybe rephrase to include that "creating a NotificationChannel" is only needed in API 26+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the comment.

var count = Intent?.Extras?.GetInt (MainActivity.COUNT_KEY, -1);

// No count was passed? Then just return.
if (count <= 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have any nullability issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Intent and Extras may be null.

var button = FindViewById<Button> (Resource.Id.MyButton);
ArgumentNullException.ThrowIfNull (button);
button.Click += ButtonOnClick;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

@rachelkang rachelkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get the notifications working on my device with API 32, but apparently it's working fine on API 31. @jonathanpeppers do you have any ideas?

@jonathanpeppers
Copy link
Member

@rachelkang do we need to add this:

https://developer.android.com/about/versions/13/changes/notification-permission

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

@jonathanpeppers jonathanpeppers merged commit 7587222 into dotnet:dotnet Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants