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

fix(android_alarm_manager_plus): Fix showIntent not being set correctly in setAlarmClock #2778

Merged

Conversation

AhsanSarwar45
Copy link
Contributor

@AhsanSarwar45 AhsanSarwar45 commented Mar 31, 2024

Description

The issue

Currently the android_alarm_manager_plus does not set the showIntent argument properly when setting an alarm clock using setAlarmClock. According to android docs, this is supposed to set a pending intent that shows the user details of the alarm, or the ability to edit the alarm. This is usually done by launching the relevant app that set the alarm. This intent is used when the user clicks on the quick setting alarm tile, or most other system UIs showing the next alarm (notification are, lock screen etc.). In the image below, the alarm tile is in the bottom left.
image
Currently, showIntent is set as the intent that triggers the alarm isolate. This means that whenever the user taps the above mentioned system UIs, the code inside the alarm isolate runs, which is not what was expected.

The fix

This PR sets the showIntent such that it launches the app, as well as passing the alarm id and params as extras to this intent. No new parameters have been added.

These extras can be used by the app to direct the user to the relevant alarm, and the relevant screen. An example of how these extras can be used in the receiving dart code using the receive_intent package.

final paramsExtra = receivedIntent.extra?["params"];
if (paramsExtra != null){
  final params = jsonDecode(params);
}
final id = receivedIntent.extra?["id"];

Related Issues

Fix #2766

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@AhsanSarwar45 AhsanSarwar45 changed the title fix (android_alarm_manager_plus): Fix showIntent not being set correctly in setAlarmClock fix(android_alarm_manager_plus): Fix showIntent not being set correctly in setAlarmClock Mar 31, 2024
Copy link
Member

@miquelbeltran miquelbeltran left a comment

Choose a reason for hiding this comment

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

Thank you! I think it is a good start, I will have to run this on my device to ensure it works as expected, but the change seems logic!

I asked for a small code change just for better readability.

I'd also like to ask you to document this somehow in the README, so plugin users are aware of this action and how can they use it.

@miquelbeltran miquelbeltran self-assigned this Mar 31, 2024
@AhsanSarwar45
Copy link
Contributor Author

@miquelbeltran Thanks for the suggestions. Applied the refactoring into a function. Also, added a section in the readme. Not sure if its too verbose, but wanted to be clear how exactly to achieve that functionality.

Copy link
Member

@miquelbeltran miquelbeltran left a comment

Choose a reason for hiding this comment

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

Tested on my phone, worked as expected, thanks for the contribution!

Merging.

@miquelbeltran miquelbeltran merged commit 7d578c3 into fluttercommunity:main Apr 3, 2024
13 checks passed
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.

[Bug]: [Alarm Manager Plus] Tapping alarm quick tile on android runs the alarm isolate
2 participants