how to get path of captured image in android

Solutions on MaxInterview for how to get path of captured image in android by the best coders in the world

showing results for - "how to get path of captured image in android"
Rafael
14 Aug 2019
1protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
2    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
3        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
4        imageView.setImageBitmap(photo);
5        knop.setVisibility(Button.VISIBLE);
6
7
8        // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
9        Uri tempUri = getImageUri(getApplicationContext(), photo);
10
11        // CALL THIS METHOD TO GET THE ACTUAL PATH
12        File finalFile = new File(getRealPathFromURI(tempUri));
13
14        System.out.println(mImageCaptureUri);
15    }  
16}
17
18public Uri getImageUri(Context inContext, Bitmap inImage) {
19    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
20    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
21    String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
22    return Uri.parse(path);
23}
24
25public String getRealPathFromURI(Uri uri) {
26    String path = "";
27    if (getContentResolver() != null) {
28        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
29        if (cursor != null) {
30            cursor.moveToFirst();
31            int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
32            path = cursor.getString(idx);
33            cursor.close();
34        }
35    }
36    return path;
37}