Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

android - camera intent data null in onActivityResult(int requestCode, int resultCode, Intent data) in Samsung S3

Problem: I am getting camera intent's data null in onActivityResult(int requestCode, int resultCode, Intent data) in Samsung S3. But working well on some other devices. I customized my code for getting data and searched this issue in web but nothing found useful.

Code :

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == TAKE_CAMERA && data != null && data.getData() != null)  

           else if (requestCode == TAKE_CAMERA) {
        if (resultCode != RESULT_OK) return;
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(tempFileUri, "image/*");

        intent.putExtra("outputX", 90);
        intent.putExtra("outputY", 90);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, CROP_CAMERA);
    } else if (requestCode == CROP_CAMERA && data != null) {
        Bitmap photo = data.getExtras().getParcelable("data");
        try {
            FileOutputStream out = new FileOutputStream(tempFileUri.getPath());
            photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (photo != null) {
            imagePhoto.setImageBitmap(photo);

            <my code>
        }

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

if you are providing MediaStore.EXTRA_OUTPUT, then the intent is null, but you will have the photo in the file you provided (Uri.fromFile(f)).

I hope below link give the solution for you.It working for me.

http://mylearnandroid.blogspot.in/2014/02/multiple-choose-custom-gallery.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...