1 Commits
Author SHA1 Message Date
ivanszabo 3d0f9ce987 Saját notify 2025-05-14 20:12:25 +02:00
9 changed files with 175 additions and 6 deletions
+11 -2
View File
@@ -8,7 +8,15 @@ using WorkFlowCheck.MAUI.DataLayer;
using WorkFlowCheck.MAUI.Helper; using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Services; using WorkFlowCheck.MAUI.Services;
using WorkFlowCheck.MAUI.Services.Interfaces; using WorkFlowCheck.MAUI.Services.Interfaces;
using Android.Content.PM;
using WorkFlowCheck.MAUI.Platforms.Android.Services;
#if ANDROID
using Android.Content;
using WorkFlowCheck.MAUI.Platforms.Android;
#endif
namespace WorkFlowCheck.MAUI namespace WorkFlowCheck.MAUI
{ {
public partial class App : Application public partial class App : Application
@@ -29,14 +37,15 @@ namespace WorkFlowCheck.MAUI
_dbContext.Database.EnsureDeleted(); // Adatbázis törlése _dbContext.Database.EnsureDeleted(); // Adatbázis törlése
_dbContext.Database.EnsureCreated(); // Új adatbázis létrehozása _dbContext.Database.EnsureCreated(); // Új adatbázis létrehozása
StartBackgroundTask();
//StartBackgroundTask();
MainPage = new AppShell(); MainPage = new AppShell();
//MainPage = new NavigationPage(new MainPage(serviceProvider.GetRequiredService<IUserService>())); //MainPage = new NavigationPage(new MainPage(serviceProvider.GetRequiredService<IUserService>()));
} }
protected async override void OnResume() protected async override void OnResume()
{ {
StartBackgroundTask(); //StartBackgroundTask();
base.OnResume(); base.OnResume();
var isLogged = await SecureStorage.Default.GetAsync("WFCUser"); var isLogged = await SecureStorage.Default.GetAsync("WFCUser");
if (isLogged == null) if (isLogged == null)
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.MAUI.Helper
{
public static class ServiceHelper
{
public static IServiceProvider Services { get; set; }
}
}
+4 -1
View File
@@ -1,7 +1,9 @@
using DevExpress.Entity.Model.Metadata; using Android.Content;
using DevExpress.Entity.Model.Metadata;
using WorkFlowCheck.Common.DTO; using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.Helper; using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Pages.Media; using WorkFlowCheck.MAUI.Pages.Media;
using WorkFlowCheck.MAUI.Platforms.Android.Services;
using WorkFlowCheck.MAUI.Services.Interfaces; using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI namespace WorkFlowCheck.MAUI
{ {
@@ -15,6 +17,7 @@ namespace WorkFlowCheck.MAUI
{ {
InitializeComponent(); InitializeComponent();
_userService = userService; _userService = userService;
} }
private void SetInfo() private void SetInfo()
+1
View File
@@ -65,6 +65,7 @@ namespace WorkFlowCheck.MAUI
ServiceProvider = app.Services; ServiceProvider = app.Services;
ServiceHelper.Services = app.Services;
return app; return app;
} }
@@ -1,8 +1,10 @@
using Android.Content;
using CommunityToolkit.Maui.Alerts; using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core; using CommunityToolkit.Maui.Core;
using System.Drawing; using System.Drawing;
using WorkFlowCheck.MAUI.Helper; using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Pages.NFC; using WorkFlowCheck.MAUI.Pages.NFC;
using WorkFlowCheck.MAUI.Platforms.Android.Services;
using WorkFlowCheck.MAUI.Services.Interfaces; using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Pages.Security; namespace WorkFlowCheck.MAUI.Pages.Security;
@@ -35,6 +37,10 @@ public partial class LoginPage : BasePage
_userService.SetCurrentUser(response.Data); _userService.SetCurrentUser(response.Data);
SystemHelper.SystemUserDTO = response.Data; SystemHelper.SystemUserDTO = response.Data;
#if ANDROID
var intent = new Intent(Android.App.Application.Context, typeof(NotifyService));
Android.App.Application.Context.StartForegroundService(intent);
#endif
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data); var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
@@ -15,6 +15,11 @@
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" /> android:resource="@xml/file_paths" />
</provider> </provider>
<service android:name="WorkFlowCheck.MAUI.Platforms.Android.Services.NotifyService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="dataSync"
android:process=":notiprocess"/>
</application> </application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@@ -23,5 +28,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-feature android:name="android.hardware.nfc" android:required="true" /> <uses-feature android:name="android.hardware.nfc" android:required="true" />
</manifest> </manifest>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -0,0 +1,124 @@
using Android.App;
using Android.Content;
using Android.OS;
using System.Threading;
using System.Threading.Tasks;
using WorkFlowCheck.MAUI.Helper;
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Platforms.Android.Services
{
[Service]
public class NotifyService : Service
{
private CancellationTokenSource _cts;
private IUserService _userService;
private ISyncService _syncService;
public NotifyService()
{
}
public override IBinder OnBind(Intent intent) => null;
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
CreateNotificationChannel();
var notification = new Notification.Builder(this, "polling_channel")
.SetContentTitle("Értesítés figyelés")
.SetContentText("A háttérfigyelés aktív")
.SetSmallIcon(Resource.Drawable.notification_icon)
.SetVisibility(NotificationVisibility.Public) // Lock screen-en is látszódjon
.SetPriority((int)NotificationPriority.High)
.Build();
StartForeground(1, notification);
_cts = new CancellationTokenSource();
var _syncService = ServiceHelper.Services.GetService(typeof(ISyncService)) as ISyncService;
var _userService = ServiceHelper.Services.GetService(typeof(IUserService)) as IUserService;
Task.Run(async () =>
{
await _syncService.SyncUsers_Down((progress, message) =>
{
});
}, _cts.Token);
var userDTO = _userService.GetCurrentUser();
if (userDTO != null && userDTO.Id > 0)
{
if (userDTO.RoleDTO?.Count > 0)
{
foreach (var roleDTO in userDTO.RoleDTO)
{
if (roleDTO.CanEnableBlocked)
{
Task.Run(async () =>
{
while (!_cts.Token.IsCancellationRequested)
{
var deviceMessageDTOList = await _syncService.DeviceMessageReadUnreaded(_userService.DeviceId.ToUpper());
if (deviceMessageDTOList != null && deviceMessageDTOList.Count > 0)
{
ShowNotification("Új esemény", deviceMessageDTOList[0].Message);
break;
}
deviceMessageDTOList = await _syncService.DeviceMessageReadUnreadedRole(roleDTO.Id);
if (deviceMessageDTOList != null && deviceMessageDTOList.Count > 0)
{
ShowNotification("Új esemény", deviceMessageDTOList[0].Message);
break;
}
await Task.Delay(5000);
}
}, _cts.Token);
}
}
}
}
return StartCommandResult.Sticky;
}
public override void OnDestroy()
{
_cts?.Cancel();
base.OnDestroy();
}
private void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
var channel = new NotificationChannel("polling_channel", "Polling Channel", NotificationImportance.High)
{
Description = "Foreground service polling channel",
LockscreenVisibility = NotificationVisibility.Public
};
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
}
private void ShowNotification(string title, string message)
{
var builder = new Notification.Builder(this, "polling_channel")
.SetContentTitle(title)
.SetContentText(message)
.SetSmallIcon(Resource.Drawable.notification_icon)
.SetAutoCancel(true)
.SetVisibility(NotificationVisibility.Public)
.SetPriority((int)NotificationPriority.High);
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.Notify(new System.Random().Next(), builder.Build());
}
}
}
@@ -31,7 +31,7 @@
<!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>--> <!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>-->
<!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>--> <!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>-->
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">29.0</SupportedOSPlatformVersion>
<!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> <!--<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>--> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>-->
@@ -159,4 +159,10 @@
<Folder Include="Platforms\Android\Resources\mipmap-xxxhdpi\" /> <Folder Include="Platforms\Android\Resources\mipmap-xxxhdpi\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AndroidResource Update="Platforms\Android\Resources\drawable\notification_icon.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AndroidResource>
</ItemGroup>
</Project> </Project>