below is my code but is not give me image path in onActivity result
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Log.w("jay", "Camera Image Path :" + selectedImagePath);
Toast.makeText(MiscansOther_pannel.this, selectedImagePath,
Toast.LENGTH_LONG).show();
Hold down the Shift key, then right-click the photo. In the context menu that appears, find and click Copy as path. This copies the file location to the clipboard.
The URI path for the image returned by camera is fetched inside the method getCaptureImageOutputUri() . The onActivityResult essentially returns a URI to the image. Some devices do return the bitmap as data. getExtras().
Intent camera_intent = new Intent(MediaStore. ACTION_IMAGE_CAPTURE); startActivityForResult(camera_intent, pic_id); Now use the onActivityResult() method to get the result, here is the captured image.
This works for me...
Code:
Uri selectedImageUri = data.getData();
selectedImagePath = getRealPathFromURI(selectedImageUri);
Method: getRealPathFromURI()
//----------------------------------------
/**
* This method is used to get real path of file from from uri
*
* @param contentUri
* @return String
*/
//----------------------------------------
public String getRealPathFromURI(Uri contentUri)
{
try
{
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
catch (Exception e)
{
return contentUri.getPath();
}
}
EDIT:
As I noticed in some device after captured image the data in onActivityResult()
is null,
So the alternate way, Pass the specific image filename as a argument to your Intent for capture image as putExtra
parameter.
Then also insert this image Uri in Media Store, Now use this Uri for your further use,
You can check whether image is captured or not by File.exist()
,
Code looks like,
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "Image File name");
Uri mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intentPicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intentPicture.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intentPicture,ACTION_TAKE_PICTURE);
Now, you can use the same method for get file path from Uri,
in this case it will be in onActivityResult()
,
selectedImagePath = getRealPathFromURI(mCapturedImageURI); // don't use data.getData() as it return null in some device instead use mCapturedImageUR uri variable statically in your code,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With