Plugin.LocalNotification
Plugin.LocalNotification copied to clipboard
Implementation of full screen intent
Is your feature request related to a problem? Please describe.
- I got a MAUI application where it is all about a reminders for taking medicines. Now I believe this kind of stuffs is time sensitive and notification on a status bar is not enough. First idea comes to my mind is that, start an activity when a notification from your library is received. I then browsed Android documentation and found this: https://developer.android.com/guide/components/activities/background-starts. I then asked ChatGPT to further elaborate this and a piece of code caught my attention:
Describe the solution you'd like
- Implement .SetFullScreenIntent() when building a notification
Describe alternatives you've considered
- Tried starting an activity from the background, nothing happens. I tried using broadcast receiver to achieve it.
- Another example is the use of foreground service, unfortunately it doesn't work.
Additional context
- I found this StackOverflow thread and it's quite promising: https://stackoverflow.com/questions/65888143/what-exactly-is-full-screen-intent-in-android
@thudugala, I managed to make this work by using native notifications. However, I would like to rely fully on your library as there's some functionality I needed. How can I send an example to further assist you?
Thanks!
@echolumaque you can do a PR with your change?
@echolumaque you can do a PR with your change?
I'm not that well versed with the your library's code and it would definitely took me a long time to understand it. Perhaps a blank project would work?
Sure just attach a sample project here 🙂
@thudugala, you can clone this project and let me know if you have any questions: https://github.com/echolumaque/FullScreenIntentNotification
Relevant files:
https://github.com/echolumaque/FullScreenIntentNotification/tree/master/Platforms/Android/Services/AlarmServices
https://github.com/echolumaque/FullScreenIntentNotification/blob/master/Platforms/Android/MainActivity.cs
On MainActivity, you can see these code:
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetShowWhenLocked(true);
SetTurnScreenOn(true);
}
I believe it is necessary to wake the device and actually show the activity. More context here: https://stackoverflow.com/a/69314329/13061894. Also, I believe ShowForAllUsers must be set to true in the Activity attribute.
These permissions are also required:
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
Attached video is how it works: https://github.com/thudugala/Plugin.LocalNotification/assets/61021721/27defa1f-2845-4e77-a878-41f883ccbdad
To replicate:
- Add a notification
- Minimize the app in the background
- Turn off the screen
@echolumaque try version 11.0.1-preview01
Make sure to set LaunchApp
var request = new NotificationRequest
{
NotificationId = notificationId,
Title = title,
Android =
{
LaunchApp = new AndroidLaunch(),
}
}
@thudugala, I've tried your instructions and unfortunately, it only just sent the notification on the status bar 😢. Tested both in simulator (Pixel 3a XL - Android 12), and physical device (Samsung Galaxy A71 - Android 12).
Here's my notification create code:
[ConfigureAwait(false)]
public async Task ScheduleNotification(string description, DateTime notifiyTime)
{
var randomIndex = Random.Shared.Next(14);
var notificationIcon = new AndroidIcon { ResourceName = "notif_icon" };
var notificationRequest = new NotificationRequest
{
Android = new AndroidOptions
{
ChannelId = "com.group10.healthmate",
IconLargeName = notificationIcon,
IconSmallName = notificationIcon,
IsGroupSummary = true,
LaunchApp = new AndroidLaunch(),
Priority = AndroidPriority.Max,
VibrationPattern = [200, 300, 200, 300, 200, 300],
VisibilityType = AndroidVisibilityType.Public
},
CategoryType = NotificationCategoryType.Alarm,
Description = description,
Group = "com.group10.healthmate",
//Image = new NotificationImage
//{
// FilePath
//},
NotificationId = Guid.NewGuid().GetHashCode(),
Schedule = new NotificationRequestSchedule
{
Android = new AndroidScheduleOptions
{
AlarmType = AndroidAlarmType.RtcWakeup,
},
NotifyTime = notifiyTime,
RepeatType = NotificationRepeat.No
},
Subtitle = notificationSubtitles[randomIndex],
Title = notificationTitles[randomIndex]
};
await _notificationService.Show(notificationRequest);
}
Please let me know if there's help that I can do. Thanks again.
@echolumaque hey can attach the full project sample?
@thudugala , hello sorry for the late reply. The project is still the same (https://github.com/echolumaque/FullScreenIntentNotification). I just pushed the changes so you can try it out. Please take a pull and let me know if how can I be of help.
Thanks again!
@echolumaque Check my last commit: https://github.com/pkozak2/FullScreenIntentNotification