I am new to Xamarin forms and coding in general, I want to check if the device has biometrics as soon as the app is launched. I came across this video that shows how to do it using a button, I wanted to use it as soon as I open the app. can you help?
btnFPLogin.Clicked += FingerPrint;
private async void FingerPrint(object sender, EventArgs e)
{
var result = await CrossFingerprint.Current.IsAvailableAsync(true);
Plugin.Fingerprint.Abstractions.FingerprintAuthenticationResult auth;
if (result)
{
try
{
var res = await App.Current.MainPage.DisplayAlert("Success", "Your data are saved", "Ok", "Cancel");
auth = await CrossFingerprint.Current.AuthenticateAsync("Authenticate access");
if (auth.Authenticated)
{
await App.Current.MainPage.DisplayAlert("Results are here", "Valid fingerprint found", "Ok");
}
else
{
await App.Current.MainPage.DisplayAlert("Results are here", "Invalid fingerprint", "Ok");
}
}
catch
{
await App.Current.MainPage.DisplayAlert("permission to use FaceID", "We need permission to use FaceID", "Ok");
}
}
}
you've answered your own question. To check if a device supports biometric login, use the CrossFingerprint plugin
var result = await CrossFingerprint.Current.IsAvailableAsync(true);
if you want to check this on app launch, put it in the OnStart method of the App class
Related
im beginner in firebase and im using two nuget packages FirebaseAuthentication.net and FirebaseDatabase.net .
im trying to write to a protected firebase realtime database that has a rule that look like this
{
"rules": {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
}
i randomly tryed SignInWithOAuthAsync method however it throws an Exception [ mail auth type connot be used like this. use method specifc to email & password authentication]
private async void Button_Clicked(object sender, EventArgs e)
{
try
{
var authProvider = new FirebaseAuthProvider(new FirebaseConfig(webApiKey));
var savedfirebaseauth = JsonConvert.DeserializeObject<FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
await authProvider.SignInWithOAuthAsync(FirebaseAuthType.EmailAndPassword, savedfirebaseauth.FirebaseToken);
//inserting info into the database
await firebaseClient.Child("users").Child("some uid1").PutAsync(new userinfo
{
firstName = "noor",
secondName = "mohammed"
});
//clear the entry
recordData.Text = "";
}catch(Exception ex)
{
await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
}
}
pleace let me know if my question needs more Clarificatio thanks in advance.
Am trying to connect to an API I built with the client version, running the client app with break points I can see that the data I pass in(signing up) gets passed down but when it get to the the PostAsync method that sends the data to the api the application breaks and I get 'system-net-webexception-failed-to-connect-to-localhost-127-0-0-1-44391' and an accompanying error that reads 'The selected debug engine does not support any code executing on the current thread (e.g. only native runtime code is executing)', there's no red highlight to indicate where the error is which makes this a real head scratcher for me.....
Some insight on the issue will be greatly appreciated.
Sub.Clicked += async (object sender, EventArgs e) =>
{
if (!Conection.IsConnected)
{
await DisplayAlert("No Connection", "Please turn on or reset your data connection", "Cancle");
}
var entirs = new string[] { Email.Text, Password.Text, FN.Text, LN.Text, Phone.Text};
var jcon = JsonConvert.SerializeObject(entirs);
var contain = new StringContent(jcon, Encoding.UTF8, "aplication/json");
message.Timeout = new TimeSpan(0, 0, 100);
var outcome = await message.PostAsync("https://localhost:5001/api/v1/identity/Register", contain);
if (outcome.StatusCode==HttpStatusCode.Created)
{
await DisplayAlert("Success", "Entries have been loaded", "X");
Application.Current.MainPage = new NavigationPage(new Selection());
}
else
{
await DisplayAlert("Failed", outcome.StatusCode.ToString(), "cancel");
};
};
I am having a login form and implementing fingerprint authentication.
I have the following code but the app crashes suddenly.
Button in xml file:
<Button Text="Scan Fingerprint" Clicked="FingerPrint_clicked"/>
Code behind this:
public async void FingerPrint_clicked(object sender, EventArgs e)
{
var cancellationToken = new System.Threading.CancellationToken();
var scanResult = await CrossFingerprint.Current.AuthenticateAsync("Show your fingerprint", cancellationToken);
if(scanResult.Authenticated)
{
await DisplayAlert(null, "done", "ok");
}
else
{
await DisplayAlert(null, "failed", "ok");
}
}
MainActivity.cs
CrossFingerprint.SetCurrentActivityResolver(()=> CrossCurrentActivity.Current.Activity);
Added fingerprint in android.manifest file
and set fingerprint in emulator too
Upon clicking the button for fingerprint test, the app crashes suddenly.
Resolved by adding this line to MainActivity.cs file:
CrossCurrentActivity.Current.Init(this, savedInstanceState);
So I am listening to the event whenever anyone on the server sends a message to any text channel with my bot. I want to detect swear words like "fuck" and change it to "f*ck".
I was unable to replace my message just normally only with reflection but it did not help since it only replaced it in the instance of the SocketMessage but it did not change the message on the server.
Any solution for that?
Framework: 4.6
Discord.NET: 1.0.2
Code:
private async Task MsgRec(SocketMessage e)
{
try
{
if (e.Content.Contains("fuck"))
{
foreach(PropertyInfo info in typeof(SocketMessage).GetProperties())
{
if (info.Name == "Content")
{
info.SetValue(e,e.Content.Replace("fuck", "f*ck"));
}
}
}
}
catch (Exception ex)
{
await e.Author.SendMessageAsync(ex.StackTrace);
}
}
Update I also tried this without any success:
var rMessage = (RestUserMessage) await e.Channel.GetMessageAsync(e.Id);
await rMessage.ModifyAsync(msg => msg.Content = e.Content.Replace("fuck", "f*ck"));
Discord, like other chat programs, does not allow you to change messages of users. You can not censor what a user wrote, you can only delete the whole message.
maybe you could try something like this
private async Task MsgRec(SocketMessage e)
{
var msg = e as SocketUserMessage;
if (msg == null) return;
if (msg.Content.Contains("fuck"))
{
var newMsg = msg.Content.Replace("fuck", "f*ck");
await Context.Channel.SendMessageAsync(newMsg);
}
}
My app has been working fine for a lot of months, but now its not working. When I handle the exception, I get: MediaElement.currentState is Closed. And get result:"Media Player not avaliable". This my code:
if (mediaElement.CurrentState.Equals(MediaElementState.Playing)) {
mediaElement.Stop();
}
else {
try {
SpeechSynthesisStream stream = await sin.SynthesizeTextToStreamAsync(texto);
// Send the stream to the media object.
mediaElement.AutoPlay = true;
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
catch (System.IO.FileNotFoundException) {
var messageDialog = new Windows.UI.Popups.MessageDialog("Media Player not avaliable");
await messageDialog.ShowAsync();
}
}
I have tested your code on my side and I cannot reproduce your issue. Since your code is not completed, I added the remain code by myself and it can run successfully now. Please compare the code snippet to find if something is wrong with your code. You can also run the following simple demo on your machine which can work well on my machine to see if it is a machine environment issue. My test environment is windows 10 build 14393.
XAML Code
<MediaElement x:Name="mediaElement"
CurrentStateChanged="MediaElement_CurrentStateChanged" Height="200" Width="300" AutoPlay="False"/>
<Button x:Name="btntest" Click="btntest_Click" Content=" media close test"></Button>
Code behind
private async void btntest_Click(object sender, RoutedEventArgs e)
{
if (mediaElement.CurrentState.Equals(MediaElementState.Playing))
{
mediaElement.Stop();
}
else
{
try
{
var sin = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
string texto = "hello world";
SpeechSynthesisStream stream= await sin.SynthesizeTextToStreamAsync(texto);
// Send the stream to the media object.
mediaElement.AutoPlay = true;
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
catch (System.IO.FileNotFoundException)
{
var messageDialog = new Windows.UI.Popups.MessageDialog("Media Player not avaliable");
await messageDialog.ShowAsync();
}
}