0

I am doing a module which needs to convert image into pdf. i have successfully implemented the camera and can display its image. but my problem is getting the uri of that image. i saw a code snippet here in StackOverflow and followed it but it returns null.

here is my sample code:

            @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
        uri = data.getData();

        if(uri == null)
        {
            tvUri.setText("null");
        }else{
            tvUri.setText(uri.toString());
        }

    }
}

to test if it is null, i proceeded to set the textview into its value if it has one, but if not, then i set it to null.

Quick learner
  • 10,632
  • 4
  • 45
  • 55
JJCADIZ
  • 143
  • 2
  • 14

2 Answers2

-1
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    Uri u = intent.getData();
}
PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35
  • this is what i did. still null – JJCADIZ May 23 '17 at 09:55
  • check it by adding breakpoints and debug then you will know data is available or not from intent. – PRATEEK BHARDWAJ May 23 '17 at 09:56
  • 1
    **From review queue**: May I request you to please add some context around your source-code. Code-only answers are difficult to understand. It will help the asker and future readers both if you can add more information in your post. – RBT May 24 '17 at 01:52
-1

try this

uri = data.getExtras().get("data");

instead of

uri = data.getData();
Junaid Fahad
  • 149
  • 7