protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); global::Xamarin.FormsMaps.Init(this, bundle); if (Android.OS.Build.VERSION.SdkInt <= Android.OS.BuildVersionCodes.M) { Permission permissionCheck = ContextCompat.CheckSelfPermission( BaseContext, Manifest.Permission.AccessFineLocation ); if (permissionCheck != Permission.Granted) { ActivityCompat.RequestPermissions( this, new String[] { Manifest.Permission.AccessFineLocation }, REQUEST_ACCESS_FINE_LOCATION ); } } LoadApplication(new App()); }
private void OnClickFaceAuthWithCrpObj(object sender, EventArgs e) { string Tag = "FaceAuthWithCrpObj"; Android.Content.PM.Permission permissionCheck = Android.Content.PM.Permission.Granted; if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { permissionCheck = CheckSelfPermission(Manifest.Permission.Camera); } if (permissionCheck != Android.Content.PM.Permission.Granted) { log.Info(Tag, "The camera permission is not enabled. Please enable it."); // request camera permissions if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { RequestPermissions(new string[] { Manifest.Permission.Camera }, 1); } return; } BioAuthnCallback callback = new FidoBioAuthnCallback(); // Cancellation Signal CancellationSignal cancellationSignal = new CancellationSignal(); FaceManager faceManager = new FaceManager(this); log.Info(Tag, $"IsHardwareDetected:{faceManager.IsHardwareDetected}"); // Checks whether 3D facial authentication can be used. int errorCode = faceManager.CanAuth(); if (errorCode != 0) { log.Info(Tag, "Can not authenticate. errorCode=" + errorCode); return; } // flags int flags = 0; // Authentication messsage handler. Handler handler = null; // Recommended CryptoObject to be set to null. KeyStore is not associated with face authentication in current // version. KeyGenParameterSpec.Builder.setUserAuthenticationRequired() must be set false in this scenario. CryptoObject crypto = null; log.Info(Tag, "Start face authentication.\nAuthenticating......\n"); faceManager.Auth(crypto, cancellationSignal, flags, callback, handler); }
/// <summary> /// 判断用户是否有权限 /// </summary> /// <param name="permissionName"></param> /// <returns></returns> public bool CheckPermission(string permissionName) { if (Xamarin.Essentials.DeviceInfo.Version.Major < 6) { #if DEBUG string msg = $"当前系统为 Android{Xamarin.Essentials.DeviceInfo.Version.Major}"; System.Diagnostics.Debug.WriteLine(msg); System.Diagnostics.Debugger.Break(); #endif return(true); } Android.Content.PM.Permission permission = mAppActivity.CheckSelfPermission(permissionName); return(permission == Android.Content.PM.Permission.Granted ? true : false); }
/// <inheritdoc /> public Task <AuthenticationResult> AuthenticateAsync(string alertMessage = null) { Permission permissionResult = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.UseFingerprint); var tcs = new TaskCompletionSource <AuthenticationResult>(); if (permissionResult == Permission.Granted) { if (AvailableBiometricType == BiometricType.None) { Logger.Debug("[BiometricAuthenticationService] Authentication not available on this device"); tcs.TrySetResult(new AuthenticationResult(false, "Authentication not available")); } else { if (_fingerprintFragmentType != null) { var fragment = Activator.CreateInstance(_fingerprintFragmentType, tcs); if (fragment is FingerprintManagerFragment customFragment) { MainApplication.CurrentActivity.RunOnUiThread(() => { customFragment.Show(MainApplication.CurrentActivity.FragmentManager, "dialog"); }); } else { throw new Exception("Specified FingerprintManagerFragment does not inherit from FingerprintManagerFragment"); } } else { var fingerPrintDialog = new FingerprintManagerFragment(_alertTitle, alertMessage ?? "Please scan fingerprint", tcs); MainApplication.CurrentActivity.RunOnUiThread(() => { fingerPrintDialog.Show(MainApplication.CurrentActivity.FragmentManager, "dialog"); }); } } } else { tcs.TrySetResult(new AuthenticationResult(false, "UseFingerprint Permission has not been granted.")); } return(tcs.Task); }