Exemplo n.º 1
0
        public Task <LocalAuthResult> AuthenticateAsync(string reason)
        {
            // CryptoObjectHelper is described in the previous section.
            var cryptoHelper = new CryptoObjectHelper();

            var context = Android.App.Application.Context;

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
            {
                /* ==================================================================================================
                 * android api 23 or higher
                 * ================================================================================================*/
                var manager = context.GetSystemService(Context.FingerprintService) as FingerprintManager;
                // cancellationSignal can be used to manually stop the fingerprint scanner.
                var cancellationSignal     = new Android.OS.CancellationSignal();
                var authenticationCallback = new SimpleAuthCallback();
                // Start the fingerprint scanner.
                manager.Authenticate(cryptoHelper.BuildCryptoObject(), cancellationSignal, FingerprintAuthenticationFlags.None, authenticationCallback, null);
            }

            // Using the Android Support Library v4
            var managerCompat = FingerprintManagerCompat.From(context);
            // cancellationSignal can be used to manually stop the fingerprint scanner.
            var cancellationSignalCompat = new Android.Support.V4.OS.CancellationSignal();
            // AuthenticationCallback is a base class that will be covered later on in this guide.
            var callbackCompat = new SimpleCompatAuthCallback();

            // Start the fingerprint scanner.
            managerCompat.Authenticate(cryptoHelper.BuildCompatCryptoObject(), 0, cancellationSignalCompat, callbackCompat, null);
            //return new LocalAuthResult(false);
            return(Task.FromResult(new LocalAuthResult(false)));
        }
Exemplo n.º 2
0
        public override void OnWrite(PageRange[] pages, Android.OS.ParcelFileDescriptor destination, Android.OS.CancellationSignal cancellationSignal, WriteResultCallback callback)
        {
            try
            {
                using (InputStream input = new FileInputStream(_filePath))
                {
                    using (OutputStream output = new FileOutputStream(destination.FileDescriptor))
                    {
                        var buf = new byte[1024];
                        int bytesRead;

                        while ((bytesRead = input.Read(buf)) > 0)
                        {
                            output.Write(buf, 0, bytesRead);
                        }
                    }
                }

                callback.OnWriteFinished(new[] { PageRange.AllPages });
            }
            catch (FileNotFoundException fileNotFoundException)
            {
                System.Diagnostics.Debug.WriteLine(fileNotFoundException);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception);
            }
        }
Exemplo n.º 3
0
        public override void OnLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, Android.OS.CancellationSignal cancellationSignal, LayoutResultCallback callback, Android.OS.Bundle extras)
        {
            if (cancellationSignal.IsCanceled)
            {
                callback.OnLayoutCancelled();
                return;
            }

            callback.OnLayoutFinished(new PrintDocumentInfo.Builder(_fileName)
                                      .SetContentType(PrintContentType.Document)
                                      .Build(), true);
        }
Exemplo n.º 4
0
        public override void OnWrite(PageRange[] pages, Android.OS.ParcelFileDescriptor destination, Android.OS.CancellationSignal cancellationSignal, WriteResultCallback callback)
        {
            InputStream  input  = null;
            OutputStream output = null;

            try {
                input  = new FileInputStream(_filePath);
                output = new FileOutputStream(destination.FileDescriptor);

                byte[] buf = new byte[1024];
                int    bytesRead;

                while ((bytesRead = input.Read(buf)) > 0)
                {
                    output.Write(buf, 0, bytesRead);
                }

                callback.OnWriteFinished(new PageRange[] { PageRange.AllPages });
            } catch (FileNotFoundException ee) {
                //Catch exception
            } catch (Exception e) {
                //Catch exception
            } finally {
                try {
                    input.Close();
                    output.Close();
                } catch (IOException e) {
                    e.PrintStackTrace();
                }
            }
        }