Skip to content

Cannot send local notification with a ScheduleDate set using 3.2.4 #1406

@munkii

Description

@munkii

Component/Nuget

Notifications (Shiny.Notifications)

What operating system(s) are effected?

  • iOS (13+ supported)
  • Mac Catalyst
  • Android (8+ supported)

Version(s) of Operation Systems

Android 12, 13 and 14 and 9 (Physical devices)

Hosting Model

  • MAUI
  • Native/Classic Xamarin
  • Manual

Steps To Reproduce

Using Shiny 3.2.4 set the ScheduleDate on the local notifcation and try and send it. Notifcation does not appear

  • Previous version 2.7.3 worked fine with Android
  • 3.2.3 works fine with iOS

Expected Behavior

I'd expect to see a scheduled notification or an error.

Permission issues with Android 14 wouldn't be that surprising and I have logged an issue with Xamarin Essentials FWIW

Actual Behavior

No error and no Notification. If I do not set the ScheduleData the notifcation happens immediately without issue

Exception or Log output

No response

Code Sample

var status = await this.scheduleExactNotificationPermission.CheckStatusAsync();
if (status != PermissionStatus.Granted)
{
    status = await this.scheduleExactNotificationPermission.RequestAsync();
}

AccessState state = await this.notificationManager.RequestAccess(AccessRequestFlags.TimeSensitivity);

if (state == AccessState.Available || status == PermissionStatus.Granted)
{
    var pendingNotificationsOnThisDevice = await this.notificationManager.GetPendingNotifications();

    if (pendingNotificationsOnThisDevice.Any(n => n.Title == title) == false)
    {
        var notification = new Notification()
        {
            Title = title,
            Message = reminderText,
            Channel = "DefaultH",
            ScheduleDate = DateTime.Now.AddMinutes(30),
        };

#if DEBUG
        notification.ScheduleDate = DateTime.Now.AddMinutes(2);
        notification.Message += " DEBUG";
#endif
        System.Diagnostics.Debug.WriteLine("RemindToCallAsync Create Scheduled Notification");

        await this.notificationManager.Send(notification);
    }
    else
    {
        // There is a pending notification to call the Nurse Team. Do not hassle user with another one.
        this.logger.LogInteraction("Pending notification. Do not add another.");
    }
}

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:usesCleartextTraffic="false" android:versionCode="1" android:versionName="3.7.0" package="com.Us.OurProjectApp" android:installLocation="auto">
	<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33" />
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.WAKE_LOCK" />
	<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
	<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.VIBRATE" />
	<uses-permission android:name="android.permission.BLUETOOTH" tools:node="replace" android:maxSdkVersion="30" />
	<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" tools:node="replace" android:maxSdkVersion="30" />
	<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
	<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" android:maxSdkVersion="30" />
	<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" tools:node="remove" android:maxSdkVersion="30" />
	<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" tools:node="replace" tools:targetApi="31" />
	<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="replace" android:usesPermissionFlags="neverForLocation" tools:targetApi="31" />
	<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
	<application android:label="US RM" android:icon="@mipmap/app_icon" Name="US RM" tools:replace="android:label">
		<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="DefaultH" />
		<activity android:name="microsoft.identity.client.BrowserTabActivity" android:exported="true">
			<intent-filter>
				<action android:name="android.intent.action.VIEW" />
				<category android:name="android.intent.category.DEFAULT" />
				<category android:name="android.intent.category.BROWSABLE" />
				<data android:scheme="msalGUIDHERE" android:host="auth" />
			</intent-filter>
		</activity>
	</application>
	<queries>
		<intent>
			<action android:name="android.support.customtabs.action.CustomTabsService" />
		</intent>
		<intent>
			<action android:name="android.intent.action.SENDTO" />
			<data android:scheme="mailto" />
		</intent>
		<intent>
			<action android:name="android.intent.action.DIAL" />
			<data android:scheme="tel" />
		</intent>
	</queries>
</manifest>

AssemblyInfo Permission attributes

[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.AccessNetworkState)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
[assembly: UsesPermission(Android.Manifest.Permission.PostNotifications)]
[assembly: UsesPermission(Android.Manifest.Permission.ScheduleExactAlarm)]
[assembly: UsesPermission(Android.Manifest.Permission.UseExactAlarm)]

Code of Conduct

  • I have supplied a reproducible sample that is NOT FROM THE SHINY SAMPLES!
  • I am a Sponsor OR I am using the LATEST stable/beta version from nuget (v3.0 stable - ALPHAS are not taking issues - Sponsors can still send v2 issues)
  • I am Sponsor OR My GitHub account is 30+ days old
  • I understand that if I am checking these boxes and I am not actually following what they are saying, I will be removed from this repository!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions