i am using hce in maui, which all works well, code below shows what i am doing. the hce system work well but the popup is not showing when in background, it only shows when running the app.
[
Service(Enabled = true, Exported = true, Permission = "android.permission.BIND_NFC_SERVICE"),
IntentFilter(new[] { global::Android.Nfc.CardEmulators.HostApduService.ServiceInterface }),
MetaData(global::Android.Nfc.CardEmulators.HostApduService.ServiceMetaData, Resource = "@xml/apduservice")
]
public class MyHostApduService : HostApduService
{
public override void OnDeactivated([GeneratedEnum] DeactivationReason reason)
{
}
public override byte[]? ProcessCommandApdu(byte[]? commandApdu, Bundle? extras)
{
var task = Task.Run<string>(async () => await SecureStorage.GetAsync("text"));
task.Wait();
var result = task.Result;
byte[]? bytes = Encoding.ASCII.GetBytes(result);
_ = ShowPopup();
return bytes;
}
public async Task ShowPopup()
{
var ConformationPopControl = new ConfirmationPopUpPage();
ConformationPopControl.Title = "Sent";
Convert.ToBoolean(await PopupAction.DisplayPopup(ConformationPopControl));
Thread.Sleep(1000);
PopupAction.ClosePopup(ConformationPopControl);
}
}
public class PopupAction
{
public static async Task<T> DisplayPopup<T>(PopUpBasePage page) where T : new()
{
try
{
if (Application.Current?.MainPage != null)
{
await Application.Current.MainPage.Navigation.PushModalAsync(page);
}
return (T)await page.returnResultTask.Task;
}
catch (Exception ex)
{
return default(T);
}
}
public static async Task<object> DisplayPopup(PopUpBasePage page)
{
try
{
if (Application.Current?.MainPage != null)
await Application.Current.MainPage.Navigation.PushModalAsync(page);
return await page.returnResultTask.Task;
}
catch (Exception ex)
{
return "";
}
}
public static async Task ClosePopup(object returnValue = null)
{
if (Application.Current?.MainPage != null && Application.Current.MainPage.Navigation.ModalStack.Count > 0)
{
try
{
var currentPage = (PopUpBasePage)Application.Current.MainPage.Navigation.ModalStack.LastOrDefault();
currentPage?.returnResultTask.TrySetResult(returnValue);
}
catch (Exception ex)
{
}
await Shell.Current.GoToAsync($"..");
}
}
}
however i want to show a popup when the data has been sent but this only works when the app is running not in background. is there a way around this.