Added: NFC Intent for Machine

This commit is contained in:
TheJoKlLa
2023-02-11 17:14:17 +01:00
parent 092081e82d
commit 4790de0f78
3 changed files with 83 additions and 16 deletions

View File

@ -4,30 +4,28 @@ using Android.Content.PM;
using Android.OS;
using AndroidX.AppCompat.App;
using Java.Interop;
using System;
namespace Borepin.Droid
{
[Activity(MainLauncher = true, Exported = true, Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[Activity(MainLauncher = true, Exported = true, Theme = "@style/MainTheme", LaunchMode = LaunchMode.SingleTask, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(
new[]
{
"android.nfc.action.NDEF_DISCOVERED"
"android.nfc.action.NDEF_DISCOVERED",
"android.intent.action.VIEW",
},
Categories = new[]
Categories = new[]
{
Intent.CategoryDefault
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataScheme = "fabaccess",
DataHost = "innovisionlab.de"
DataScheme = "fabaccess"
)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
Android.Net.Uri test = Intent.Data;
string text = Intent.GetStringExtra("MyData") ?? "Data not available";
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
TabLayoutResource = Resource.Layout.Tabbar;
@ -39,10 +37,22 @@ namespace Borepin.Droid
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App(new PlatformInitializer()));
Android.Net.Uri intentdata = Intent.Data;
Uri uri = null;
if (intentdata != null)
{
uri = new Uri(intentdata.ToString());
}
LoadApplication(new App(new PlatformInitializer(), uri));
}
protected override void OnNewIntent(Intent intent)
{
if(intent.Action == "android.nfc.action.NDEF_DISCOVERED")
{
intent.SetAction(Intent.ActionView);
}
base.OnNewIntent(intent);
}

View File

@ -7,9 +7,9 @@ namespace Borepin.Droid
[Application(Label = "FabAccess", Icon = "@mipmap/ic_launcher")]
public class MainApplication : Application
{
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
}
}