Permissions 安卓牛轧糖许可

Permissions 安卓牛轧糖许可,permissions,camera,android-7.1-nougat,Permissions,Camera,Android 7.1 Nougat,伙计们,我从棒棒糖变成了牛轧糖,我正试图让我的相机在我的应用程序中拍照 我知道您现在必须在运行时授予权限,并尝试了以下操作 static final Integer CAMERA = 0x5; public void onCreate(Bundle savedInstanceState) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.La

伙计们,我从棒棒糖变成了牛轧糖,我正试图让我的相机在我的应用程序中拍照

我知道您现在必须在运行时授予权限,并尝试了以下操作

static final Integer CAMERA = 0x5;

public void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        askForPermission(Manifest.permission.CAMERA,CAMERA);
 }

private void askForPermission(String permission, Integer requestCode) {

    Toast.makeText(this, permission, Toast.LENGTH_SHORT).show();
    if (ContextCompat.checkSelfPermission(newstart.this, permission) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(newstart.this, permission)) {

            //This is called if user has denied the permission before
            //In this case I am just asking the permission again
            ActivityCompat.requestPermissions(newstart.this, new String[]{permission}, requestCode);

        } else {

            ActivityCompat.requestPermissions(newstart.this, new String[]{permission}, requestCode);
        }
    } else {
        Toast.makeText(this, "" + permission + " is already granted.", Toast.LENGTH_SHORT).show();
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if(ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED){
        Toast.makeText(this, "Permission check", Toast.LENGTH_SHORT).show();
        switch (requestCode) {
            //Location
            case 1:

                break;

            //Write external Storage
            case 3:
                break;
            //Read External Storage
            case 4:
                Intent imageIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(imageIntent, 11);
                break;
            //Camera
            case 5:
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(takePictureIntent, 12);
                }
                break;

        }

        Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
    }else{
        Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
    }
}
这是我的应用程序启动时的第一个活动,无论我尝试什么,它都会拒绝我的祝酒权限,并且不会让我授予权限

如果我只是尝试拍照,它会使应用程序崩溃,因此我知道我需要授予使用相机的权限

知道我哪里出错了吗

谢谢你的帮助


不再允许标记文件:/。 您应该通过content://scheme发送URI,这是内容提供者的URI方案。


您还可以将目标SDK从24更改为23,它将修复此问题。(不推荐)

不再允许使用file://文件。 您应该通过content://scheme发送URI,这是内容提供者的URI方案。

您还可以将目标SDK从24更改为23,它将修复它。(不推荐)