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

Implementation of full screen intent #458

Open
echolumaque opened this issue Nov 19, 2023 · 10 comments
Open

Implementation of full screen intent #458

echolumaque opened this issue Nov 19, 2023 · 10 comments
Labels
Android Android only issue enhancement New feature or request

Comments

@echolumaque
Copy link

echolumaque commented Nov 19, 2023

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:

    image

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

@echolumaque echolumaque added the enhancement New feature or request label Nov 19, 2023
@thudugala thudugala added the Android Android only issue label Nov 20, 2023
@echolumaque
Copy link
Author

@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!

@thudugala
Copy link
Owner

@echolumaque you can do a PR with your change?

@echolumaque
Copy link
Author

@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?

@thudugala
Copy link
Owner

Sure just attach a sample project here 🙂

@echolumaque
Copy link
Author

echolumaque commented Nov 21, 2023

@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

@thudugala
Copy link
Owner

@echolumaque try version 11.0.1-preview01

Make sure to set LaunchApp

 var request = new NotificationRequest
 {
     NotificationId = notificationId,
     Title = title,
     Android =
     {
        LaunchApp = new AndroidLaunch(),
     }
}

@echolumaque
Copy link
Author

echolumaque commented Nov 23, 2023

@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.

@thudugala
Copy link
Owner

@echolumaque hey can attach the full project sample?

@echolumaque
Copy link
Author

echolumaque commented Nov 24, 2023

@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!

@pkozak2
Copy link

pkozak2 commented Mar 5, 2024

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

3 participants