Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Nougat 7.0 camera problem #9

Closed
skined90 opened this issue Aug 16, 2016 · 12 comments
Closed

Android Nougat 7.0 camera problem #9

skined90 opened this issue Aug 16, 2016 · 12 comments
Labels

Comments

@skined90
Copy link

When I open camera, it just crash.

android.os.FileUriExposedException: file:///storage/emulated/0/Pictures/Camera/IMG_20160816_135126.jpg exposed beyond app through ClipData.Item.getUri()

@parkjaeiek
Copy link

parkjaeiek commented Aug 23, 2016

my think 7.0 change file access

Passing file:// URIs outside the package domain may leave the receiver with an unaccessible path. Therefore, attempts to pass a file:// URI trigger a FileUriExposedException. The recommended way to share the content of a private file is using the FileProvider.

from : https://developer.android.com/about/versions/nougat/android-7.0-changes.html

@andhie
Copy link

andhie commented Aug 24, 2016

This is my changes to fix the issue

    private void captureImage() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(getPackageManager()) != null) {
//            fileTemp = ImageUtils.getOutputMediaFile();
            ContentValues values = new ContentValues(1);
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg");
            fileUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//            if (fileTemp != null) {
//            fileUri = Uri.fromFile(fileTemp);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            startActivityForResult(intent, REQUEST_CODE_CAPTURE);
//            } else {
//                Toast.makeText(this, getString(R.string.error_create_image_file), Toast.LENGTH_LONG).show();
//            }
        } else {
            Toast.makeText(this, getString(R.string.error_no_camera), Toast.LENGTH_LONG).show();
        }
    }

@nguyenhoanglam
Copy link
Owner

@andhie Thank you very much for your contribution. Currently I don't have Android N to check your code. As soon as I successfully install Android N on the emulator, I'll let you know. Now I'm fixing other bugs and adding some features. I hope you keep supporting this library to make it more useful!

Thanks!

@jhandei
Copy link

jhandei commented May 20, 2017

Any workaround for this issue?

@chandragithub2014
Copy link

java.lang.SecurityException: Not allowed to start activity Intent { act=android.intent.action.GET_CONTENT typ=/ } . I got the above exception when I try to launch camera

@nguyenhoanglam
Copy link
Owner

Please update to the latest version and let me know if it's works!

@Nonisharma
Copy link

Hi all is that issue resolved now please rply i am in trouble

@nguyenhoanglam
Copy link
Owner

@Nonisharma what's wrong with you?

@revarb
Copy link

revarb commented Feb 11, 2018

@andhie
Thank you So much.
It works Properly.

@isaabdullahi2008
Copy link

am trying to display the picture and upload to server, but is crashing using the below code
BitmapFactory.Options options = new BitmapFactory.Options();

        // down sizing image as it throws OutOfMemory Exception for larger
        // images
        options.inSampleSize = 5;

        String filePath = fileUri.getPath();

        //Bitmap bitmapCamera = BitmapFactory.decodeFile(filePath, options);
        Bitmap bitmapCamera = (Bitmap) data.getExtras().get("data");

       //Bitmap bitmap = (Bitmap)data.getExtras().get("data");
       //Bundle extras = data.getExtras();
       //Bitmap bitmapCamera = (Bitmap) extras.get("data");


        Bitmap bmp = null;
        try {
            bmp = changeOrientation(bitmapCamera, filePath);
        } catch (IOException e) {
            e.printStackTrace();
        }

        ByteArrayOutputStream outPut = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, outPut);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //bmp.compress(Bitmap.CompressFormat.JPEG, 70, baos);
        byte[] imageBytes = outPut.toByteArray();
        encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);

        imgView.setImageBitmap(bmp);

@ghost
Copy link

ghost commented Aug 8, 2018

After capture image always getting image rotated and i also try to get orientation code but getting all time orientation 0 .
File f = new File(uri);
ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int angle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
angle = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
angle = 180;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
angle = 270;
}

            Matrix mat = new Matrix();
            mat.postRotate(angle);

please suggest me right thing for nougat. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants