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

Users can't enable the reminder for the app #503

Open
erossini opened this issue May 31, 2024 · 4 comments
Open

Users can't enable the reminder for the app #503

erossini opened this issue May 31, 2024 · 4 comments
Assignees
Labels
Android Android only issue bug Something isn't working

Comments

@erossini
Copy link

erossini commented May 31, 2024

In my NET8 MAUI apps, I want to send a local notification every day to remind the user to use the app. For that, I'm using the component Plugin.LocalNotification. For Android, in the AndroidManifest.xml, I added those lines

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

<!--Required so that the plugin can reschedule notifications upon a reboot-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Then I created a service to manage the notification and checked if the user gave the consent to use the app.

INotificationService _notificationService;
var notifyDateTime = DateTime.Parse($"{DateTime.Now.ToShortDateString()} {settings.StudyAlertTime}");
var notification = new NotificationRequest
{
    NotificationId = 100,
    Title = AppResources.NotificationsTitle,
    Description = AppResources.NotificationDescription,
    CategoryType = NotificationCategoryType.Status,
    Android = new Plugin.LocalNotification.AndroidOption.AndroidOptions
    {
        AutoCancel = true,
        IconSmallName =
        {
            ResourceName = "noti_liulogo",
        },
        IconLargeName =
        {
            ResourceName = "liulogo",
        },
        LaunchAppWhenTapped = true,
        Priority = AndroidPriority.High
    },
    iOS =
    {
        HideForegroundAlert = true,
        PlayForegroundSound = true
    },
    Schedule =
    {
        NotifyTime = notifyDateTime,
        RepeatType = NotificationRepeat.Daily
    }
};

await _notificationService.Show(notification);

When the app runs this code, the user is redirected to the system page to enable Alarms and reminders but the switch is disabled.

enter image description here

What have I done wrong?

@erossini erossini added the bug Something isn't working label May 31, 2024
@erossini erossini changed the title User can't enable the app to send local notification Users can't enable the reminder for the app May 31, 2024
@erossini
Copy link
Author

erossini commented Jun 5, 2024

An update. If I added in the AndroidManifest.xml the lines

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

the application can send notifications but rejected by Google Play. Without those lines, the app shows the authorization page but I can't enable the notifications.

image

This is the same in emulators or real devices with Android API 33 or above.

@thudugala
Copy link
Owner

@erossini can you set Unrestricted battery mode in Android settings for your app and try again

@erossini
Copy link
Author

erossini commented Jun 5, 2024

@erossini can you set Unrestricted battery mode in Android settings for your app and try again

What permission is that?

@thudugala
Copy link
Owner

@thudugala thudugala added the Android Android only issue label Jun 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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants