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);
            }
        }
Exemplo n.º 3
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.º 4
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);
            }
        }
        /**
         * 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);
            }
        }