授予权限后,Android例外权限是否被拒绝?

时间:2019-12-22 14:58:09

标签: java android

我在做什么错? 我已经尝试过googlign这个问题,但人们大多说这是android Q的问题,但我不认为我的问题是这个。

AndroidManifest.xml:

<manifest ...>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

Java:

void takePhoto(){

    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA},2);

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null)
    {
            File photoFile = createPhotoFile();
            if(photoFile != null){
                pathToFile = photoFile.getAbsolutePath();
                Uri photoURI = getUriForFile(this, this.getPackageName() + ".fileprovider", photoFile);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, REQUEST_CAMERA);
            }
        }

}

private File createPhotoFile() {
    String name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File image = null;
    try{
        image = File.createTempFile(name, ".jpg", storageDir);
    } catch(IOException e){
        Log.d("myLog", "Except: " + e.toString());
    }
    return image;
}

0 个答案:

没有答案