Android 相机未打开,用于具有工作配置文件的设备

Android 相机未打开,用于具有工作配置文件的设备,android,permissions,intune,Android,Permissions,Intune,最近,我们的设备设置为具有工作配置文件。我们使用Microsoft Intune进行设备管理 我们注意到,具有此工作配置文件设置的设备不能再使用其设备的照相机或多媒体资料。没有工作配置文件设置的设备仍然可以使用这些功能 在应用程序中,我们通常会在需要权限时询问权限,但在通过工作配置文件安装应用程序时,不会询问这些权限。在检查应用程序设置中的权限时,我们无法更改它们,但它表示已为相机和存储授予权限。我还检查了关于如何使用工作配置文件处理相机意图的来源。我们已经完全按照前面的解释实现了这一点 对于未

最近,我们的设备设置为具有工作配置文件。我们使用Microsoft Intune进行设备管理

我们注意到,具有此工作配置文件设置的设备不能再使用其设备的照相机或多媒体资料。没有工作配置文件设置的设备仍然可以使用这些功能

在应用程序中,我们通常会在需要权限时询问权限,但在通过工作配置文件安装应用程序时,不会询问这些权限。在检查应用程序设置中的权限时,我们无法更改它们,但它表示已为相机和存储授予权限。我还检查了关于如何使用工作配置文件处理相机意图的来源。我们已经完全按照前面的解释实现了这一点

对于未设置工作配置文件的设备,我们可以在拒绝相机和存储器的权限时重现该问题。那么行为就完全一样了。在需要使用相机的工作配置文件(如Outlook)的设备上使用不同的应用程序时,可以使用该应用程序,并显示Toast消息,说明相机在工作配置文件之外使用

下面是我们用来启动相机的代码。我们有一个片段内的活动:


public class CreateAttachmentActivity extends AppCompatActivity implements ColorChooserDialog.ColorCallback {
    private CreateAttachmentFragment createAttachmentFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_attachment);
        if (checkCameraPermissions()) {
            initView();
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(LocaleManager.onAttach(base, getCurrentUser().getPreferredLanguage()));
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (requestCode == Constants.REQUEST_CAMERA_PERMISSIONS) {
            if (isPermissionsGranted(grantResults)) {
                initView();
            } else {
                Toast.makeText(getContext(), getContext().getString(R.string.camera_permission_not_granted), Toast.LENGTH_LONG).show();
                finish();
            }
        } else {
            Toast.makeText(getContext(), getContext().getString(R.string.wrong_permission_requested), Toast.LENGTH_LONG).show();
            finish();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        this.createAttachmentFragment.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onColorSelection(@NonNull ColorChooserDialog dialog, int selectedColor) {
        createAttachmentFragment.onColorSelection(dialog, selectedColor);
    }

    @Override
    public void onColorChooserDismissed(@NonNull ColorChooserDialog dialog) {
        createAttachmentFragment.onColorChooserDismissed(dialog);
    }


    private void initView() {
        this.createAttachmentFragment = CreateAttachmentFragment.newInstance();
        RippleView backButton = findViewById(R.id.backButton);
        getSupportFragmentManager().beginTransaction().add(R.id.pictureContainer, createAttachmentFragment).commit();
        backButton.setOnRippleCompleteListener(rippleView -> onBackPressed());
    }

    private boolean checkCameraPermissions() {
        List<String> requiredPermissions = getRequiredPermissions();
        if (PermissionUtils.applicationHasPermissions(this, requiredPermissions)) {
            return true;
        } else {
            ActivityCompat.requestPermissions(this, new String[]{
                    Manifest.permission.CAMERA,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE}, Constants.REQUEST_CAMERA_PERMISSIONS);
            return false;
        }
    }

    private static List<String> getRequiredPermissions() {
        return Arrays.asList(
                Manifest.permission.CAMERA,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
        );
    }
}
你知道这个问题可能来自哪里吗

问候

private void openCameraView() {
        try {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File imageFile = AttachmentUtils.createImageFile(requireContext());
            if (intent.resolveActivity(requireActivity().getPackageManager()) != null) {
                this.imagePath = imageFile.getAbsolutePath();
                Uri uri = FileProvider.getUriForFile(requireContext(), requireContext().getPackageName().concat(Constants.AUTHORITY_FILEPROVIDER), imageFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setClipData(ClipData.newRawUri(null, uri));
                requireActivity().startActivityForResult(intent, Constants.INTENT_CAMERA);
            } else {
                Toast.makeText(getContext(), requireContext().getString(R.string.gallery_camera_not_opening_fallback), Toast.LENGTH_LONG).show();
            }
        } catch (IOException e) {
            Log.e(TAG, Log.getStackTraceString(e));
            onLoadImageError(true);
        }
    }