Firebase teszthez
This commit is contained in:
@@ -12,7 +12,12 @@ using Microsoft.Maui.Hosting;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using WorkFlowCheck.MAUI.Handlers;
|
||||
using WorkFlowCheck.MAUI.Helper;
|
||||
using Plugin.Firebase.CloudMessaging;
|
||||
using Microsoft.Maui.LifecycleEvents;
|
||||
|
||||
#if ANDROID
|
||||
using Plugin.Firebase.Core.Platforms.Android;
|
||||
#endif
|
||||
namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
public static class MauiProgram
|
||||
@@ -23,7 +28,7 @@ namespace WorkFlowCheck.MAUI
|
||||
builder.UseDevExpress(useLocalization: false)
|
||||
.UseDevExpressControls()
|
||||
.UseDevExpressCollectionView();
|
||||
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddDbContext<AppDbContext>();
|
||||
@@ -46,7 +51,7 @@ namespace WorkFlowCheck.MAUI
|
||||
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
|
||||
fonts.AddFont("FontAwesome.ttf", "FontAwesome");
|
||||
})
|
||||
|
||||
.RegisterFirebaseServices()
|
||||
.UseMauiCommunityToolkitCore()
|
||||
.UseMauiCommunityToolkit();
|
||||
#if DEBUG
|
||||
@@ -63,11 +68,24 @@ namespace WorkFlowCheck.MAUI
|
||||
}).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
ServiceProvider = app.Services;
|
||||
return app;
|
||||
}
|
||||
|
||||
public static IServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
|
||||
|
||||
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
|
||||
{
|
||||
builder.ConfigureLifecycleEvents(events =>
|
||||
{
|
||||
#if ANDROID
|
||||
events.AddAndroid(android => android.OnCreate((activity, _) =>
|
||||
CrossFirebase.Initialize(activity)));
|
||||
#endif
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using CommunityToolkit.Maui.Alerts;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using Plugin.Firebase.CloudMessaging;
|
||||
using System.Drawing;
|
||||
using WorkFlowCheck.MAUI.Helper;
|
||||
using WorkFlowCheck.MAUI.Pages.NFC;
|
||||
@@ -14,6 +15,7 @@ public partial class LoginPage : BasePage
|
||||
public LoginPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitFirebase();
|
||||
SetContent(LoginContent);
|
||||
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
|
||||
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
|
||||
@@ -166,4 +168,18 @@ public partial class LoginPage : BasePage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async void InitFirebase()
|
||||
{
|
||||
try
|
||||
{
|
||||
await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
|
||||
var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
|
||||
Console.WriteLine($"FCM token: {token}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("FCM init error: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,18 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="default" />
|
||||
<receiver
|
||||
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
|
||||
android:exported="true"
|
||||
android:permission="com.google.android.c2dm.permission.SEND">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
||||
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
||||
<category android:name="${applicationId}" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
@@ -23,5 +35,8 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-feature android:name="android.hardware.nfc" android:required="true" />
|
||||
</manifest>
|
||||
@@ -3,6 +3,8 @@ using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Nfc;
|
||||
using Android.OS;
|
||||
using Firebase;
|
||||
using Plugin.Firebase.CloudMessaging;
|
||||
using Plugin.NFC;
|
||||
|
||||
|
||||
@@ -40,12 +42,14 @@ namespace WorkFlowCheck.MAUI
|
||||
new Intent(this, typeof(MainActivity)).AddFlags(ActivityFlags.SingleTop),
|
||||
Build.VERSION.SdkInt >= BuildVersionCodes.S ? PendingIntentFlags.Mutable : PendingIntentFlags.UpdateCurrent);
|
||||
|
||||
HandleIntent(Intent);
|
||||
CreateNotificationChannelIfNeeded();
|
||||
}
|
||||
|
||||
protected override void OnNewIntent(Intent intent)
|
||||
{
|
||||
base.OnNewIntent(intent);
|
||||
|
||||
HandleIntent(intent);
|
||||
CrossNFC.OnNewIntent(intent);
|
||||
|
||||
if (intent.Action == NfcAdapter.ActionTagDiscovered)
|
||||
@@ -85,5 +89,24 @@ namespace WorkFlowCheck.MAUI
|
||||
// nfcAdapter?.DisableForegroundDispatch(this);
|
||||
//}
|
||||
}
|
||||
private static void HandleIntent(Intent intent)
|
||||
{
|
||||
FirebaseCloudMessagingImplementation.OnNewIntent(intent);
|
||||
}
|
||||
private void CreateNotificationChannelIfNeeded()
|
||||
{
|
||||
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
|
||||
{
|
||||
CreateNotificationChannel();
|
||||
}
|
||||
}
|
||||
private void CreateNotificationChannel()
|
||||
{
|
||||
var channelId = $"{PackageName}.general";
|
||||
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
||||
var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
|
||||
notificationManager.CreateNotificationChannel(channel);
|
||||
FirebaseCloudMessagingImplementation.ChannelId = channelId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<resources>
|
||||
<string name="com.google.firebase.crashlytics.mapping_file_id">none</string>
|
||||
</resources>
|
||||
@@ -36,7 +36,9 @@
|
||||
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
|
||||
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
|
||||
<GoogleServicesJson Include="Platforms\Android\google-services.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- App Icon -->
|
||||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
|
||||
@@ -54,6 +56,9 @@
|
||||
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
|
||||
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Remove="Platforms\Android\Resources\values\strings.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Platforms\Android\Resources\xml\file_paths.xml" />
|
||||
|
||||
Reference in New Issue
Block a user