// GET THE URI FROM THE IMAGE (YOU NEED A BITMAP FOR THIS - WORKAROUND FOLLOWS)
Uri tempUri = getImageUri(getApplicationContext(), bitmap);
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
// THE WORKAROUND (OPTIONAL IN CASE YOU DO NOT HAVE A BITMAP)
Bitmap bitmap = ((BitmapDrawable)youImageView.getDrawable()).getBitmap();
Credit: https://stackoverflow.com/a/8306683/450534
// NOW THAT YOU WILL HAVE THE URI, USE THIS TO GET THE ABSOLUTE PATH OF THE IMAGE
File finalFile = new File(getRealPathFromURI(tempUri));
public String getRealPathFromURI(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
In my experience with Android, the only need I ever had this was when I started working on the Twitter4J SDK and the TwitPic API. TwitPic needs the absolute path of the Image you want to upload. This was the best solution I found (a combination of several different solutions actually) but it has always worked like a charm. Hope it helps you.