简体   繁体   中英

Camera intent resultCode always return cancelled for Nougat

When I am using camera intent in Nouget versions camera intent working perfectly.

My Problem: But resultCode (onActivityResult()) always return cancelled.

Note: Same code return result correctly in older versions. I am facing only in Nougat

My code:

    private void takePicture(Activity context) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) {
        Uri photoURI = null;
        try {
            File file = new File(Environment
                    .getExternalStorageDirectory(), "temp.jpg");

            String path = file.getAbsolutePath();
            photoURI = FileProvider.getUriForFile(context,
                    context.getPackageName() + ".provider",
                    file);
        } catch (Exception e) {
            Log.e(TAG, "takePicture: ", e);
        }
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);          
        context.startActivityForResult(takePictureIntent, CAMERA_REQUEST);
    }
}

With help of this tutorial

I just solved this issue by removing android: launchMode = "singleInstance" in my AndroidManifest.xml.

This problem also occurred with ImagePicker plugin Crop plugin ...

I hope this will help somebody.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM