#if UNITY_ANDROID
using System;
using Unity.Notifications.Android;
using UnityEngine.Assertions;
namespace NotificationSamples.Android
{
///
/// Android specific implementation of .
///
public class AndroidGameNotification : IGameNotification
{
private AndroidNotification internalNotification;
///
/// Gets the internal notification object used by the mobile notifications system.
///
public AndroidNotification InternalNotification => internalNotification;
///
///
/// On Android, if the ID isn't explicitly set, it will be generated after it has been scheduled.
///
public int? Id { get; set; }
///
public string Title { get => InternalNotification.Title; set => internalNotification.Title = value; }
///
public string Body { get => InternalNotification.Text; set => internalNotification.Text = value; }
///
/// Does nothing on Android.
///
public string Subtitle { get => null; set {} }
///
public string Data { get => InternalNotification.IntentData; set => internalNotification.IntentData = value; }
///
///
/// On Android, this represents the notification's channel, and is required. Will be configured automatically by
/// if is set
///
/// The value of .
public string Group { get => DeliveredChannel; set => DeliveredChannel = value; }
///
public int? BadgeNumber
{
get => internalNotification.Number != -1 ? internalNotification.Number : (int?)null;
set => internalNotification.Number = value ?? -1;
}
///
public bool ShouldAutoCancel
{
get => InternalNotification.ShouldAutoCancel;
set => internalNotification.ShouldAutoCancel = value;
}
///
public DateTime? DeliveryTime
{
get => InternalNotification.FireTime;
set => internalNotification.FireTime = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// Gets or sets the channel for this notification.
///
public string DeliveredChannel { get; set; }
///
public bool Scheduled { get; private set; }
///
public string SmallIcon { get => InternalNotification.SmallIcon; set => internalNotification.SmallIcon = value; }
///
public string LargeIcon { get => InternalNotification.LargeIcon; set => internalNotification.LargeIcon = value; }
///
/// Instantiate a new instance of .
///
public AndroidGameNotification()
{
internalNotification = new AndroidNotification();
}
///
/// Instantiate a new instance of from a delivered notification
///
/// The notification that has been delivered.
/// The ID of the delivered notification.
/// The channel the notification was delivered to.
internal AndroidGameNotification(AndroidNotification deliveredNotification, int deliveredId,
string deliveredChannel)
{
internalNotification = deliveredNotification;
Id = deliveredId;
DeliveredChannel = deliveredChannel;
}
///
/// Set the scheduled flag.
///
internal void OnScheduled()
{
Assert.IsFalse(Scheduled);
Scheduled = true;
}
}
}
#endif