Exemplo n.º 1
0
        public void ShowCamera(View view)
        {
            Log.Info(TAG, "Show camera button pressed. Checking permission.");

            // Check if the Camera permission is already available.
            if (PermissionUtil.HasSelfPermission(this, Manifest.Permission.Camera))
            {
                // Camera permissions is already available, show the camera preview.
                Log.Info(TAG, "CAMERA permission has already been granted. Displaying camera preview.");
                ShowCameraPreview();
            }
            else
            {
                // Camera permission has not been granted.
                Log.Info(TAG, "CAMERA permission has NOT been granted. Requesting permission.");

                // Provide an additional rationale to the user if the permission was not granted
                // and the user would benefit from additional context for the use of the permission.
                if (ShouldShowRequestPermissionRationale(Manifest.Permission.Camera))
                {
                    Log.Info(TAG, "Displaying camera permission rationale to provide additional context.");
                    Toast.MakeText(this, Resource.String.permission_camera_rationale, ToastLength.Short).Show();
                }

                // Request Camera permission.
                RequestPermissions(new string[] { Manifest.Permission.Camera }, REQUEST_CAMERA);
            }
        }
Exemplo n.º 2
0
        public void ShowContacts(View v)
        {
            Log.Info(TAG, "Show contacts button pressed. Checking permissions.");

            // Verify that all required contact permissions have been granted.
            if (PermissionUtil.HasSelfPermission(this, PERMISSIONS_CONTACT))
            {
                // Contact permissions have been granted. Show the contacts fragment.
                Log.Info(TAG, "Contact permissions have already been granted. Displaying contact details.");
                ShowContactDetails();
            }
            else
            {
                // Contacts permissions have not been granted.
                Log.Info(TAG, "Contact permissions has NOT been granted. Requesting permission.");

                // Provide an additional rationale to the user if the permission was not granted
                // and the user would benefit from additional context for the use of the permission.
                if (ShouldShowRequestPermissionRationale(Manifest.Permission.ReadContacts) ||
                    ShouldShowRequestPermissionRationale(Manifest.Permission.WriteContacts))
                {
                    Log.Info(TAG, "Displaying contacts permission rationale to provide additional context.");
                    Toast.MakeText(this, Resource.String.permission_contacts_rationale, ToastLength.Short).Show();
                }

                // Request Contact permission.
                RequestPermissions(PERMISSIONS_CONTACT, REQUEST_CONTACTS);
            }
        }
 private void SetUpVirtualDisplay()
 {
     Log.Info(TAG, "Setting up a VirtualDisplay: " + surfaceView.Width + "x" + surfaceView.Height + " (" + screenDensity + ")");
     virtualDisplay = mediaProjection.CreateVirtualDisplay("ScreenCapture",
                                                           surfaceView.Width, surfaceView.Height, screenDensity,
                                                           (DisplayFlags)VirtualDisplayFlags.AutoMirror, surface, null, null);
     buttonToggle.SetText(Resource.String.stop);
 }
        public void ShowCamera(View view)
        {
            Log.Info(TAG, "Show camera button pressed. Checking permission.");

            // Check if the Camera permission is already available.
            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != (int)Permission.Granted)
            {
                // Camera permission has not been granted
                RequestCameraPermission();
            }
            else
            {
                // Camera permissions is already available, show the camera preview.
                Log.Info(TAG, "CAMERA permission has already been granted. Displaying camera preview.");
                ShowCameraPreview();
            }
        }
Exemplo n.º 5
0
        public void ShowContacts(View v)
        {
            Log.Info(TAG, "Show contacts button pressed. Checking permissions.");

            // Verify that all required contact permissions have been granted.
            if (PermissionUtil.HasSelfPermission(this, PERMISSIONS_CONTACT))
            {
                Log.Info(TAG, "Contact permissions have already been granted. Displaying contact details.");
                // Contact permissions have been granted. Show the contacts fragment.
                ShowContactDetails();
            }
            else
            {
                Log.Info(TAG, "Contact permissions has NOT been granted. Requesting permission.");
                // contact permissions has not been granted (read and write contacts). Request them.
                RequestPermissions(PERMISSIONS_CONTACT, REQUEST_CONTACTS);
            }
        }
Exemplo n.º 6
0
        public void ShowCamera(View view)
        {
            Log.Info(TAG, "Show camera button pressed. Checking permission.");

            // Check if the Camera permission is already available.
            if (PermissionUtil.HasSelfPermission(this, Manifest.Permission.Camera))
            {
                Log.Info(TAG, "CAMERA permission has already been granted. Displaying camera preview.");
                // Camera permissions is already available, show the camera preview.
                ShowCameraPreview();
            }
            else
            {
                Log.Info(TAG, "CAMERA permission has NOT been granted. Requesting permission.");
                // Camera permission has not been granted. Request it.
                RequestPermissions(new string[] { Manifest.Permission.Camera }, REQUEST_CAMERA);
            }
        }
        public void ShowContacts(View v)
        {
            Log.Info(TAG, "Show contacts button pressed. Checking permissions.");

            // Verify that all required contact permissions have been granted.
            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.ReadContacts) != (int)Permission.Granted ||
                ActivityCompat.CheckSelfPermission(this, Manifest.Permission.WriteContacts) != (int)Permission.Granted)
            {
                // Contacts permissions have not been granted.
                Log.Info(TAG, "Contact permissions has NOT been granted. Requesting permissions.");
                RequestContactsPermissions();
            }
            else
            {
                // Contact permissions have been granted. Show the contacts fragment.
                Log.Info(TAG, "Contact permissions have already been granted. Displaying contact details.");
                ShowContactDetails();
            }
        }
        /**
         * Callback received when a permissions request has been completed.
         */
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
        {
            if (requestCode == REQUEST_CAMERA)
            {
                // Received permission result for camera permission.
                Log.Info(TAG, "Received response for Camera permission request.");

                // Check if the only required permission has been granted
                if (grantResults.Length == 1 && grantResults[0] == Permission.Granted)
                {
                    // Camera permission has been granted, preview can be displayed
                    Log.Info(TAG, "CAMERA permission has now been granted. Showing preview.");
                    Snackbar.Make(layout, Resource.String.permission_available_camera, Snackbar.LengthShort).Show();
                }
                else
                {
                    Log.Info(TAG, "CAMERA permission was NOT granted.");
                    Snackbar.Make(layout, Resource.String.permissions_not_granted, Snackbar.LengthShort).Show();
                }
            }
            else if (requestCode == REQUEST_CONTACTS)
            {
                Log.Info(TAG, "Received response for contact permissions request.");

                // We have requested multiple permissions for contacts, so all of them need to be
                // checked.
                if (PermissionUtil.VerifyPermissions(grantResults))
                {
                    // All required permissions have been granted, display contacts fragment.
                    Snackbar.Make(layout, Resource.String.permission_available_contacts, Snackbar.LengthShort).Show();
                }
                else
                {
                    Log.Info(TAG, "Contacts permissions were NOT granted.");
                    Snackbar.Make(layout, Resource.String.permissions_not_granted, Snackbar.LengthShort).Show();
                }
            }
            else
            {
                base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }
        /**
         * Requests the Contacts permissions.
         * If the permission has been denied previously, a SnackBar will prompt the user to grant the
         * permission, otherwise it is requested directly.
         */
        void RequestContactsPermissions()
        {
            if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.ReadContacts) ||
                ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.WriteContacts))
            {
                // Provide an additional rationale to the user if the permission was not granted
                // and the user would benefit from additional context for the use of the permission.
                // For example, if the request has been denied previously.
                Log.Info(TAG, "Displaying contacts permission rationale to provide additional context.");

                // Display a SnackBar with an explanation and a button to trigger the request.
                Snackbar.Make(layout, Resource.String.permission_contacts_rationale,
                              Snackbar.LengthIndefinite).SetAction(Resource.String.ok, new Action <View> (delegate(View obj) {
                    ActivityCompat.RequestPermissions(this, PERMISSIONS_CONTACT, REQUEST_CONTACTS);
                })).Show();
            }
            else
            {
                // Contact permissions have not been granted yet. Request them directly.
                ActivityCompat.RequestPermissions(this, PERMISSIONS_CONTACT, REQUEST_CONTACTS);
            }
        }
        /**
         * Requests the Camera permission.
         * If the permission has been denied previously, a SnackBar will prompt the user to grant the
         * permission, otherwise it is requested directly.
         */
        void RequestCameraPermission()
        {
            Log.Info(TAG, "CAMERA permission has NOT been granted. Requesting permission.");

            if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.Camera))
            {
                // Provide an additional rationale to the user if the permission was not granted
                // and the user would benefit from additional context for the use of the permission.
                // For example if the user has previously denied the permission.
                Log.Info(TAG, "Displaying camera permission rationale to provide additional context.");

                Snackbar.Make(layout, Resource.String.permission_camera_rationale,
                              Snackbar.LengthIndefinite).SetAction(Resource.String.ok, new Action <View> (delegate(View obj) {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, REQUEST_CAMERA);
                })).Show();
            }
            else
            {
                // Camera permission has not been granted yet. Request it directly.
                ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, REQUEST_CAMERA);
            }
        }
        public override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            if (requestCode == REQUEST_MEDIA_PROJECTION)
            {
                if (resultCode != (int)Result.Ok)
                {
                    Log.Info(TAG, "User cancelled");
                    Toast.MakeText(Activity, Resource.String.user_cancelled, ToastLength.Short).Show();
                    return;
                }
                if (Activity == null)
                {
                    return;
                }

                Log.Info(TAG, "Starting screem capture");
                this.resultCode = resultCode;
                this.resultData = data;
                SetUpMediaProjection();
                SetUpVirtualDisplay();
            }
        }
 private void StartScreenCapture()
 {
     if (surface == null || Activity == null)
     {
         return;
     }
     if (mediaProjection != null)
     {
         SetUpVirtualDisplay();
     }
     else if (resultCode != 0 && resultData != null)
     {
         SetUpMediaProjection();
         SetUpVirtualDisplay();
     }
     else
     {
         Log.Info(TAG, "Requesting confirmation");
         // This initiates a prompt for the user to confirm screen projection.
         StartActivityForResult(mediaProjectionManager.CreateScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);
     }
 }