1

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

Vijay
  • 2,005
  • 1
  • 14
  • 15

2 Answers2

2

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

Community
  • 1
  • 1
Dharmendra
  • 33,296
  • 22
  • 86
  • 129
0

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));

Vijay
  • 2,005
  • 1
  • 14
  • 15