The type or namespace name 'Datetime' could not be found

Error is :
Assets\Scripts\AndroidNotificationsHandler.cs(11,38): error CS0246: The type or namespace name ‘Datetime’ could not be found (are you missing a using directive or an assembly reference?)

Please Tell me how can i solve this issue please help me:
My Code is :

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Notifications.Android;
using UnityEngine;

public class AndroidNotificationsHandler : MonoBehaviour
{
    private const string ChannelId = "notification_channel";
    public void ScheduleNotification(Datetime datetime)
    {
        AndroidNotificationChannel notificationChannel = new AndroidNotificationChannel
        {
          Id = ChannelId,
          Name = "Notification Channel",
          Description = "Some random description",
          Importance = Importance.Default
        };
        AndroidNotificationCenter.RegisterNotificationChannel(notificationChannel);
        AndroidNotification notification = new AndroidNotification
        {
           Title = "Energy Recharged!",
           Text = "Your energy has recharged, come back to play again!",
           SmallIcon = "default",
           LargeIcon = "default",
           FireTime = System.datetime
        };
        AndroidNotificationCenter.SendNotification(notification, ChannelId);
    }
}

Issue Solved by adding :

System.DateTime;

Now Here is my code:

using System;
using System.Collections;
using System.Collections.Generic;
#if UNITY_ANDROID
using Unity.Notifications.Android;
#endif
using UnityEngine;

public class AndroidNotificationHandler : MonoBehaviour
{
#if UNITY_ANDROID
private const string ChannelId = “notification_channel”;

public void ScheduleNotification(System.DateTime dateTime)
{
    AndroidNotificationChannel notificationChannel = new AndroidNotificationChannel
    {
        Id = ChannelId,
        Name = "Notification Channel",
        Description = "Some random description",
        Importance = Importance.Default
    };

    AndroidNotificationCenter.RegisterNotificationChannel(notificationChannel);

    AndroidNotification notification = new AndroidNotification
    {
        Title = "Energy Recharged!",
        Text = "Your energy has recharged, come back to play again!",
        SmallIcon = "default",
        LargeIcon = "default",
        FireTime = dateTime
    };

    AndroidNotificationCenter.SendNotification(notification, ChannelId);
}

#endif
}

The error is actually much simpler. In your original code, you’ve used

Datetime dateTime;

but the actual class is

DateTime dateTime;

C# is strongly typed and case sensitive.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms