Background NFC Reader with Shiny and Shiny.NFC #947
Replies: 1 comment
-
Hi Brian Shiny.Nfc is not not designed for background at the moment because the setup on the iOS side can go in so many different routes. Even when NFC is done "in the background", it ultimately is just opening the app on both platforms anyhow. There isn't the concept of "true" background with NFC. For your error with continuousread, you are doing a big "no no" in terms of Shiny sets of rules. Delegates (including startup tasks) should NEVER touch the UI. Anything UI related, especially on Android, needs an active activity which won't be ready by the time a startup task fires, hence the null reference exception. I'm going to make a few suggestions here because I really feel you are going down the wrong path in several ways
|
Beta Was this translation helpful? Give feedback.
-
Hi All,
I'am trying to set up a Android POC app with Shiny that reads an RFID card and puts the card Id up on a local notification. I have used the built in Shiny.Nfc code and altered it slightly to not need a full NDef payload and just return the Byte[] of the Id. Its all registered with the Shiney DI container and I created a ShinyModule and a ShinyStartup service to start the NfcManager with ContinuousRead.
As soon as I start the ContinousRead I get an error regarding a null reference using Activity.getWindow()
If I start the ContinousRead from a button on my MainPage.xaml then it all works in the foreground but stops as soon as the application goes to the background.
Looking at the Shiny.Nfc code it looks like it was designed to run in the foreground as it seems to needs an Activity with a window for the call to EnableReaderMode:
adapter.EnableReaderMode(
this.context.CurrentActivity,
this,
NfcReaderFlags.NfcA |
NfcReaderFlags.NfcB |
NfcReaderFlags.NfcBarcode |
NfcReaderFlags.NfcF |
NfcReaderFlags.NfcV,
new Android.OS.Bundle()
);
Does the Shiny framework get around this somehow or do we have to write a completely different NfcManager for background use? If the Shiny framework somehow mocks a foreground how do I register the service to use it properly?
I have looked through the Shiny source code and all of the examples but cannot find a way to do anything differently. I am using the source generated MainActivity and have written my own MainApplication to register the new NfcManager.
namespace ElevateNfc.Droid
{
[global::Android.App.ApplicationAttribute]
public partial class MainApplication : global::Android.App.Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) {}
}
The point for discussion I suppose is have I interpreted what Shiny.Nfc is doing on Android correctly? Should Shiny.Nfc work in the background out of the box or is it designed to be foreground only?
Sorry for the length of this message but I'm trying to get my head around a lot of concepts here.
Regards
Brian
Beta Was this translation helpful? Give feedback.
All reactions