0

I am making a module that needs to scan from an image taken by the camera. so basically, it converts jpeg into a PDF.

I am done accessing the camera and retrieving the bitmap too. my problem is how to get the URI and pass it to the class that converts it to the pdf. It does not give any errors in android monitor so i don't know what i'm doing wrong.

below is my code:

    public void selectImages() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, CAMERA_REQUEST);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == INTENT_REQUEST_GET_IMAGES && resultCode == Activity.RESULT_OK)
    {
        photo = (Bitmap) data.getExtras().get("data");
        uri = data.getData();

        if(uri.equals(""))
        {
            Toast.makeText(AddUtility.this, "empty", Toast.LENGTH_SHORT).show();
        } else {
            CreatePDF();
        }
    }
}

public void CreatePDF()
{
    Document document = new Document(PageSize.A4, 38, 38, 50, 38);
    try{
        PdfWriter.getInstance(document,new FileOutputStream("Sample.pdf"));
        document.open();
        Image image = Image.getInstance (uri.getPath());
        document.add(new Paragraph("Heading"));
        document.add(image);
        document.close();
    } catch (Exception e)
    {
        e.printStackTrace();
        Toast.makeText(AddUtility.this, e.toString(), Toast.LENGTH_SHORT).show();
    }
}
JJCADIZ
  • 143
  • 2
  • 14
  • your code of getting seems fine. any error log you are oberserving? – Abdul Waheed May 22 '17 at 16:27
  • no errors. even from the exception – JJCADIZ May 22 '17 at 16:42
  • ok can you please tell me what are you getting when you call uri.getpath() method? – Abdul Waheed May 22 '17 at 16:45
  • now i have an error. java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.jjcadiz.omas/com.example.jjcadiz.omas.CameraTest}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference – JJCADIZ May 22 '17 at 16:56

0 Answers0