mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Added: NFC Intent for Machine
This commit is contained in:
parent
092081e82d
commit
4790de0f78
@ -4,30 +4,28 @@ using Android.Content.PM;
|
|||||||
using Android.OS;
|
using Android.OS;
|
||||||
using AndroidX.AppCompat.App;
|
using AndroidX.AppCompat.App;
|
||||||
using Java.Interop;
|
using Java.Interop;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Borepin.Droid
|
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(
|
[IntentFilter(
|
||||||
new[]
|
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",
|
DataScheme = "fabaccess"
|
||||||
DataHost = "innovisionlab.de"
|
|
||||||
)]
|
)]
|
||||||
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
||||||
{
|
{
|
||||||
protected override void OnCreate(Bundle savedInstanceState)
|
protected override void OnCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
Android.Net.Uri test = Intent.Data;
|
|
||||||
string text = Intent.GetStringExtra("MyData") ?? "Data not available";
|
|
||||||
|
|
||||||
|
|
||||||
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
|
AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
|
||||||
|
|
||||||
TabLayoutResource = Resource.Layout.Tabbar;
|
TabLayoutResource = Resource.Layout.Tabbar;
|
||||||
@ -39,10 +37,22 @@ namespace Borepin.Droid
|
|||||||
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
||||||
|
|
||||||
Xamarin.Forms.Forms.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)
|
protected override void OnNewIntent(Intent intent)
|
||||||
{
|
{
|
||||||
|
if(intent.Action == "android.nfc.action.NDEF_DISCOVERED")
|
||||||
|
{
|
||||||
|
intent.SetAction(Intent.ActionView);
|
||||||
|
}
|
||||||
|
|
||||||
base.OnNewIntent(intent);
|
base.OnNewIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ namespace Borepin.Droid
|
|||||||
[Application(Label = "FabAccess", Icon = "@mipmap/ic_launcher")]
|
[Application(Label = "FabAccess", Icon = "@mipmap/ic_launcher")]
|
||||||
public class MainApplication : Application
|
public class MainApplication : Application
|
||||||
{
|
{
|
||||||
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer)
|
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
|
||||||
: base(javaReference, transfer)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,26 +13,83 @@ using System;
|
|||||||
using Borepin.Service.Storage;
|
using Borepin.Service.Storage;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Borepin.Service.ErrorMessage;
|
using Borepin.Service.ErrorMessage;
|
||||||
|
using Prism.Navigation.Xaml;
|
||||||
|
using Prism.Navigation;
|
||||||
|
using Borepin.Service;
|
||||||
|
using FabAccessAPI;
|
||||||
|
using FabAccessAPI.Schema;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Borepin
|
namespace Borepin
|
||||||
{
|
{
|
||||||
public partial class App
|
public partial class App
|
||||||
{
|
{
|
||||||
public App(IPlatformInitializer platformInitializer) : base(platformInitializer)
|
private readonly Uri _Intent;
|
||||||
|
public App(IPlatformInitializer platformInitializer, Uri intent = null) : base(platformInitializer)
|
||||||
{
|
{
|
||||||
var config = new NLog.Config.LoggingConfiguration();
|
NLog.Config.LoggingConfiguration config = new NLog.Config.LoggingConfiguration();
|
||||||
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
|
NLog.Targets.ConsoleTarget logconsole = new NLog.Targets.ConsoleTarget("logconsole");
|
||||||
config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole);
|
config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole);
|
||||||
LogManager.Configuration = config;
|
LogManager.Configuration = config;
|
||||||
|
|
||||||
|
_Intent = intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnInitialized()
|
protected override async void OnInitialized()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
if(_Intent!= null)
|
||||||
|
{
|
||||||
|
Prism.Navigation.NavigationParameters parameters = new Prism.Navigation.NavigationParameters
|
||||||
|
{
|
||||||
|
{ "intent", _Intent },
|
||||||
|
};
|
||||||
|
|
||||||
|
await NavigationService.NavigateAsync(new Uri("https://borepin.fab-access.org/StartPage"), parameters).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await NavigationService.NavigateAsync(new Uri("https://borepin.fab-access.org/StartPage")).ConfigureAwait(false);
|
await NavigationService.NavigateAsync(new Uri("https://borepin.fab-access.org/StartPage")).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override async void OnAppLinkRequestReceived(Uri uri)
|
||||||
|
{
|
||||||
|
if(uri.LocalPath.StartsWith("/resource/", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
string resource_id = uri.LocalPath.Remove(0, "/resource/".Length);
|
||||||
|
|
||||||
|
if (Container.IsRegistered<IAPIService>())
|
||||||
|
{
|
||||||
|
IAPIService apiService = Container.Resolve<IAPIService>();
|
||||||
|
IAPI api = apiService.GetAPI();
|
||||||
|
if (api.IsConnected)
|
||||||
|
{
|
||||||
|
if (string.Equals(uri.Host, api.ConnectionData.Host.Host, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
Optional<Machine> optional = await api.Session.MachineSystem.Info.GetMachine(resource_id).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (optional.Just == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Prism.Navigation.NavigationParameters parameters = new Prism.Navigation.NavigationParameters
|
||||||
|
{
|
||||||
|
{ "instance", optional.Just.Id },
|
||||||
|
};
|
||||||
|
|
||||||
|
Device.BeginInvokeOnMainThread(async () =>
|
||||||
|
{
|
||||||
|
INavigationResult result = await Container.Resolve<INavigationService>().NavigateAsync("/MainPage/NavigationPage/MachineListPage/MachinePage", parameters).ConfigureAwait(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||||
{
|
{
|
||||||
#region Register Basic Navigation
|
#region Register Basic Navigation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user