You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#if __ANDROID__usingAndroid;usingAndroid.App;usingAndroid.Content;usingAndroid.Content.PM;usingAndroid.OS;usingAndroid.Support.V4.App;usingAndroid.Util;usingAndroid.Views;usingAndroidX.Core.App;usingAndroidX.Lifecycle;usingSystem;namespaceProjectSBS.Services.Notifications;// TODO: Rename to AndroidNotificationServicepublicclassNotificationService:NotificationServiceBase{privateContextcontext=Android.App.Application.Context;publicNotificationService(){}publicoverrideboolIsEnabledOnDevice(){if(Build.VERSION.SdkInt>=BuildVersionCodes.N){//TODO Returns true on all//return true;}returnNotificationManagerCompat.From(context).AreNotificationsEnabled();}publicoverridevoidShowInAppNotification(stringnotification,boolautoHide){InvokeInAppNotificationRequested(newInAppNotificationRequestedEventArgs{NotificationText=notification,NotificationTime=autoHide?1500:0});}publicoverrideasyncvoidScheduleNotification(stringid,stringtitle,stringtext,DateOnlyday,TimeOnlytime){if(!IsEnabledOnDevice()){//TODO make this not only for not scheduled notifications varcurrent=awaitApplicationActivity.GetCurrent(newCancellationToken());if(ActivityCompat.CheckSelfPermission(current,Manifest.Permission.PostNotifications)!=Android.Content.PM.Permission.Granted){ActivityCompat.RequestPermissions(current,newstring[]{Manifest.Permission.PostNotifications},1);}}id=Guid.NewGuid().ToString();DateTimenotificationDateTime=new(day.Year,day.Month,day.Day,time.Hour,time.Minute,time.Second);longtotalMilliSeconds=(long)(notificationDateTime.ToUniversalTime()-DateTime.Now).TotalMilliseconds;text+=$" Scheduled for {notificationDateTime}";var(manager,intent)=CreateAlarm(id,title,text,notificationDateTime);GetAlarm();manager.SetExact(AlarmType.ElapsedRealtime,totalMilliSeconds,intent);}private(AlarmManager,PendingIntent)CreateAlarm(stringid,stringtitle,stringtext,DateTimenotificationDateTime){if(notificationDateTime>DateTime.Now){IntentnotificationIntent=new(context,typeof(NotificationReceiver));notificationIntent.PutExtra("id",id);notificationIntent.PutExtra("title",title);notificationIntent.PutExtra("text",text);varrandom=newRandom();intrequestCode=random.Next(0,5000);// TODO: ID here You can convert the id to an integer for the requestCodePendingIntentpendingIntent=PendingIntent.GetBroadcast(context,requestCode,notificationIntent,PendingIntentFlags.Immutable);AlarmManageralarmManager=(AlarmManager)context.GetSystemService(Context.AlarmService);return(alarmManager,pendingIntent);}//TODO throw new Exception("Desired time was set in the past.");return(null,null);}// TODO: Test this function properlypublicoverridevoidRemoveScheduledNotifications(stringid){IntentnotificationIntent=new(context,typeof(NotificationReceiver));notificationIntent.PutExtra("id",id);varrandom=newRandom();intrequestCode=random.Next(0,5000);// TODO: ID here You can convert the id to an integer for the requestCodePendingIntentpendingIntent=PendingIntent.GetBroadcast(context,requestCode,notificationIntent,PendingIntentFlags.Immutable);AlarmManageralarmManager=(AlarmManager)context.GetSystemService(Context.AlarmService);alarmManager.Cancel(pendingIntent);}privatevoidGetAlarm(){AlarmManageralarmManager=(AlarmManager)context.GetSystemService(Context.AlarmService);//var c = alarmManager.CanScheduleExactAlarms();//var d = alarmManager.NextAlarmClock;}publicoverridevoidShowBasicToastNotification(stringtitle,stringdescription){varnotificationManager=(NotificationManager)context.GetSystemService(Context.NotificationService);varchannelId="ProjectSBS-channel";varchannelName="Other";varimportance=NotificationImportance.High;varnotificationChannel=newNotificationChannel(channelId,channelName,importance);notificationManager.CreateNotificationChannel(notificationChannel);varnotificationBuilder=newNotificationCompat.Builder(context,channelId).SetSmallIcon(Resource.Drawable.abc_vector_test).SetContentTitle(title).SetContentText(description).SetAutoCancel(true);varnotification=notificationBuilder.Build();notificationManager.Notify(0,notification);}}[BroadcastReceiver(Enabled=true)]publicclassNotificationReceiver:BroadcastReceiver{publicoverridevoidOnReceive(Contextcontext,Intentintent){stringid=intent.GetStringExtra("id");stringtitle=intent.GetStringExtra("title");stringtext=intent.GetStringExtra("text");varnotificationManager=(NotificationManager)context.GetSystemService(Context.NotificationService);PendingIntentpendingIntent=PendingIntent.GetActivity(context,0,intent,PendingIntentFlags.Immutable);varchannelId=id;varchannelName=id;// TODO: Change from id to Item namevarimportance=NotificationImportance.High;varnotificationChannel=newNotificationChannel(channelId,channelName,importance);notificationManager.CreateNotificationChannel(notificationChannel);varnotificationBuilder=newNotificationCompat.Builder(context,channelId).SetSmallIcon(Resource.Drawable.abc_vector_test).SetContentTitle(title).SetContentText(text).SetPriority(NotificationCompat.PriorityHigh).SetContentIntent(pendingIntent).SetAutoCancel(true);varnotification=notificationBuilder.Build();notificationManager.Notify(0,notification);}}
#endif
The text was updated successfully, but these errors were encountered:
https://api.github.com/morning4coffe-dev/project-sbs/blob/eb2e3fb54ca95468f4058c6b18678cf3be478426/ProjectSBS/ProjectSBS/Services/Notification/NotificationService.cs#L102
The text was updated successfully, but these errors were encountered: