0

Help pls, how i can get URI from camera Picture i check some articals and don't understand how dows it works, pls explain me or give some links on this topic here's my code:

    private void createDirectory() {
    directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Meassure Preassure Pic");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE_PHOTO && resultCode == RESULT_OK) {
        if (intent != null && intent.getExtras() != null) {
            Bitmap imageBitmap = (Bitmap) intent.getExtras().get("data");
            ivPhoto.setImageBitmap(imageBitmap);
        }
    }
}
public void onClickPhoto(View view) {
    Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (pictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(pictureIntent, REQUEST_CODE_PHOTO);
    }
}
  • 2
    Possible duplicate of [Get uri from camera intent in android](https://stackoverflow.com/questions/21388586/get-uri-from-camera-intent-in-android) – Manohar Sep 19 '18 at 12:27
  • Possible duplicate of [How to get uri of captured photo?](https://stackoverflow.com/questions/47448297/how-to-get-uri-of-captured-photo) – Enthusiast Martin Sep 19 '18 at 12:38

1 Answers1

0

The onActivityResult method contains the data. Firstly you need to check if the data is null, after that you can use getdata() on returned intent to get URI. You can also get the real path of the captured image if you want to. Below is the code sample :

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_GALLERY_CODE && resultCode == Activity.RESULT_OK) {
        uri = data.getData();
        String filePath = getRealPathFromURIPath(uri, getActivity());
        File file = new File(filePath);
        Log.d(TAG, "Filename " + file.getName()); 
    }
}
Adnan khalil
  • 134
  • 1
  • 9