Vijay
Vijay

Reputation: 2005

Display image capture using camera in android device

i want's to display image capture using device camera and for that i have used below code.but i am getting null value in data that is return in onActivityResult .so please provide me solution for that..

thanks,

and my code is:

          File root = new File(Environment.getExternalStorageDirectory()+"/TestCameraGallery");
                 root.mkdirs();
                 MyCameraGallery = new File(root, "mycamerapicname");

                 Uri outputFileUri = Uri.fromFile(MyCameraGallery );

                 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                 intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

                 startActivityForResult(intent, CAMERA_PIC_REQUEST);

     @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data);

            if(requestCode == CAMERA_PIC_REQUEST)
    {
        Uri uri = data.getData();
             }
     }

value of uri is null and give null pointer exception so please help me

Upvotes: 1

Views: 1872

Answers (2)

Dharmendra
Dharmendra

Reputation: 34026

Using your code you will get low resolution image. If you wanna get the high resolution image you can refer this answer.

And also you can refer this blog

Upvotes: 2

Vijay
Vijay

Reputation: 2005

get solution finally


       String  imageName = "image.jpg" ;    

       ContentValues values = new ContentValues();

        values.put(MediaStore.Images.Media.TITLE, imageName);

       uri_captureImage = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri_captureImage);

        startActivityForResult(intent, requestCode_camera);



and in onAcitivity for result


String[] projection = new String[] {MediaStore.Images.Media.DATA};

     Cursor cursor = managedQuery(uri_captureImage, projection, null, null, null);
     cursor.moveToFirst();

String capimage_path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));

Upvotes: 0

Related Questions