Xamarin android BiometricPrompt.AuthenticationCallback OnAuthenticationError not available - xamarin.android

There is no override method for 'OnAuthenticationError' callback in Xamarin android version of BiometricPrompt.AuthenticationCallback class. How can I handle any error callbacks in that case?
Native android has following override methods
void onAuthenticationError(int errorCode, CharSequence errString)
void onAuthenticationFailed()
void onAuthenticationHelp(int helpCode, CharSequence helpString)
void
onAuthenticationSucceeded(BiometricAuthenticator.AuthenticationResult
result)
void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult
result)
https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.AuthenticationCallback.html
while xamarin android only has the following
void OnAuthenticationHelp ([GeneratedEnum] BiometricAcquiredStatus
helpCode, string helpString)
void OnAuthenticationHelp
([GeneratedEnum] BiometricAcquiredStatus helpCode, ICharSequence helpString)
OnAuthenticationHelp ([GeneratedEnum] BiometricAcquiredStatus helpCode, string helpString)
void OnAuthenticationFailed ();

It is claimed that this binding issue is fixed in Xamarin.Android 9.2. You may want to update your Xamarin.Android version and see if it works.
https://learn.microsoft.com/en-us/xamarin/android/release-notes/9/9.2
https://developercommunity.visualstudio.com/content/problem/399276/missing-method-bindings-in-androidhardwarebiometri.html
https://github.com/xamarin/xamarin-android/pull/2545

Related

How to represent object** in Java with graalvm native image?

I'm consuming a C library in Java with GraalVm and I have this function I don't know how to implement:
interfaces_t** tt_full_list_iface();
This is my interfaces_t struct in Java
#CStruct(value = "interfaces_t")
public interface InterfacesT extends PointerBase {
#CField("name")
CCharPointer getName();
#CField("name")
void setName(CCharPointer name);
#CField("description")
CCharPointer getDescription();
#CField("description")
void setDescription(CCharPointer description);
#CField("friendly_name")
CCharPointer getFriendlyName();
#CField("friendly_name")
void setFriendlyName(CCharPointer friendlyName);
}
And my question is: How can I implement the native function that returns this struct?
#CFunction("tt_full_list_iface")
public static native InterfacesT(?) getFullListOfInterfaces();

Why BiometricPrompt API in Xamarin Android doesn't contain onAuthenticationError Callback

In Android Studios BiometricPrompt API contains a callback named onAuthenticationError which gets triggered when the user touch outside the BiometricPrompt dialog and once a user tries to input an invalid Biometric to the device. But the BiometricPrompt API available in Xamarin.Android platform doesn't provide onAuthenticationError callback.
I created an android application using Android Studios to check BiometricPrompt API there I could access the callback named onAuthenticationError. Then I deployed the application to a device and debugged the application. The above mentioned callback got triggered when I touched any area outside the BiometricPrompt dialog and it also got triggered every time I provided BiometricPrompt with a invalid input more than 5 times.
Then I tried developing the same application in Xamain.Android and there I was unable to find any callback named onAuthenticationError. When I deployed and tested the application in a device as the above-mentioned callback was not available I couldn't handle the 2 scenarios
where when the user touches any area outside the BiometricPrompt dialog and when user provides the BiometricPrompt with an invalid input more than 5 times.
My Native android code snippet.
#RequiresApi(api = Build.VERSION_CODES.P)
private BiometricPrompt.AuthenticationCallback getAuthenticationCallback() {
return new BiometricPrompt.AuthenticationCallback() {
#Override
** public void onAuthenticationError(int errorCode,
CharSequence errString) {
notifyUser("Authentication error: " + errString);
super.onAuthenticationError(errorCode, errString);
}**
#Override
public void onAuthenticationHelp(int helpCode,
CharSequence helpString) {
super.onAuthenticationHelp(helpCode, helpString);
}
#Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
#Override
public void onAuthenticationSucceeded(
BiometricPrompt.AuthenticationResult result) {
notifyUser("Authentication Succeeded");
super.onAuthenticationSucceeded(result);
}
};
}
My Xamarin.Android code snippet
public class BiometricAuthCallBacks : BiometricPrompt.AuthenticationCallback
{
public TaskCompletionSource<LocalAuthStatus> promise = new TaskCompletionSource<LocalAuthStatus>();
private int failCount;
public override void OnAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result)
{
base.OnAuthenticationSucceeded(result);
promise.TrySetResult(LocalAuthStatus.Success);
//Success(result);
}
public override void OnAuthenticationFailed()
{
base.OnAuthenticationFailed();
failCount++;
if (failCount>=5)
{
promise.TrySetResult(LocalAuthStatus.Fail);
}
//Failed();
}
public override void OnAuthenticationHelp([GeneratedEnum] BiometricAcquiredStatus helpCode, ICharSequence helpString)
{
base.OnAuthenticationHelp(helpCode, helpString);
promise.TrySetResult(LocalAuthStatus.Error);
//Help(helpCode, helpString);
}
}
My Question is why can't I access onAuthenticationError callback from Xamarin.Android platform and how can I resolve this?

Start an Android activity in Xamarin Forms?

I am trying to view a hosted PDF file with the default Android pdf viewer in my App with the following code
var intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.Parse("http://sample/url.pdf"), "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
Android.Content.Context.StartActivity(intent);
I have used this code in a Native project, so I know that it works within an Android activity. For Xamarin Forms, is there a way for me to start an Android activity from a content page, and vice versa?
You can use DependencyService to implement this function:
INativePages in PCL:
public interface INativePages
{
void StartActivityInAndroid();
}
Implement the interface in Xamarin.Android:
[assembly: Xamarin.Forms.Dependency(typeof(NativePages))]
namespace PivotView.Droid
{
public class NativePages : INativePages
{
public NativePages()
{
}
public void StartAc()
{
var intent = new Intent(Forms.Context, typeof(YourActivity));
Forms.Context.StartActivity(intent);
}
}
}
Start an Android Activity in PCL :
private void Button_Clicked(object sender, EventArgs e)
{
Xamarin.Forms.DependencyService.Register<INativePages>();
DependencyService.Get<INativePages>().StartAc();
}
Forms.Context is obsolete now.
The workaround is to instantiate the current context in Main activity class of Android project as under:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public static Xamarin.Forms.Platform.Android.FormsAppCompatActivity Instance { get; private set; }
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
Instance = this;
}
And retrieve the local context in your NativePages StartAc() method as under:
public void StartAc()
{
var intent = new Intent(MainActivity.Instance, typeof(YourActivity));
MainActivity.Instance.StartActivity(intent);
}
Create an class for this function in an android project:
public class PdfLauncher : IPdfLauncher
{
public void LaunchPdf(string url)
{
//implementation
}
}
Create an interface in a portable project
public interface IPdfLauncher
{
void LaunchPdf(string url);
}
Add a property to your viewmodel so you can call the function from your portable project
public IPdfLauncher PdfLauncher {get;set;}
Add the interface to your viewmodel constructor and pass in an instance that you create in your android main activity. You can now call android code from your xforms commands and, if you ever add iOS or UWP you can simply implement that interface in those projects and pass them in at runtime. I use an injection framework from MVVM to automate creating these platform specific implementations, and I'd recommend you look into it if you find yourself doing these often.

does appium supports the windows desktop app(which is developed in QT) automation

I'm facing no such element exception, even though I have provided the valid element property i.e. name.
Does Appium supports the windows app which is developed in QT?
[TestClass]
public class UnitTest1
{
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/wd/hub";
protected static WindowsDriver Session;
protected static RemoteWebElement Result;
[ClassInitialize]
public static void setup(TestContext context)
{
// Launch the app
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("platformName", "Windows");
appCapabilities.SetCapability("deviceName", "WindowsPC");
appCapabilities.SetCapability("app", #"C:\****\Plus\abcd.exe");
Session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/wd/hub"), appCapabilities);
Assert.IsNotNull(Session);
Session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60));
}
[TestMethod]
public void lsapVerfication()
{
Session.FindElementByName("Logs").Click();
}

How can I get FilePicker working properly on certain BlackBerry handsets?

I'm implementing a Filepicker in my app to allow users to choose photos from their phones. The code I'm using is as follows:
Calling the Filepicker:
try
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
FilePicker fp = FilePicker.getInstance();
fileListener = new FilePickListener();
fp.setListener(fileListener);
fp.show();
}
});
}
catch (Exception e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Please check your data card..");
}
});
}
And the method to get the filename in my FilePickListener:
public void selectionDone(String str)
{
this.currFileName = str;
int index = str.lastIndexOf('/');
Dialog.alert("Filename: "+str.substring(index+1).trim());
}
This works perfectly in most handsets that I've tried it on (which have been a mix of handsets with some running OS5 and some running OS6). But on some, like the 8900 (running OS v5.0.0.411) it doesn't work properly. The Filepicker gets called and appears, but when any file gets selected, the selectionDone method doesn't get called. I've tested it on two separate 8900s and both have the same problem.
Does anyone have an idea why it works on certain handsets and not other?
You are a victim of a known RIM issue: FilePicker throws ControlledAccessException.
The issue is marked as "Fixed". However there is no info in which OS version they fixed it. (Is it so difficult to tell such a useful info?)
But from the comments to the issue:
We experience the very same issue with OS 5.0.0.321 on a Bold 9700. However, the issue does NOT appear on OS 5.0.0.464
so my guess would be they fixed it in OS 5.0.0.464. But that's not the end - in OS 6 FilePicker appears broken in early versions of OS 6 again. The conclusion - just don't use it. Use a custom file browser screen to pick a file. There is a sample in SDK 4.7.0 named FileExplorerDemo, check it for implementation details.
This is a known issue. FilePicker does not open on some devices and return an error, like the 8900 device. You can catch this error on some devices by adding the catch (Error e) { }
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
FilePicker fp = FilePicker.getInstance();
fileListener = new FilePickListener();
fp.setListener(fileListener);
fp.show();
}
});
}
catch (Exception e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("Please check your data card..");
}
});
}
catch (Error e)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("This device does not support File Picker");
}
});
}

Resources