Tuesday, January 8, 2013

Get path of stored image


How to get the path of stored image  from camera intent:

public void startCamera()
 {
         
   Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageName = String.valueOf(System.currentTimeMillis())+ ".jpg"; 
imageUri = Uri.fromFile(file);   intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
 startActivityForResult(intent, IMAGE_CAPTURE);
          }
         
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                           
         super.onActivityResult(requestCode, resultCode, data);
       if (requestCode == IMAGE_CAPTURE) {
                       if (resultCode == RESULT_OK) {
                                               
  Uri selectedImageUri = data.getData();
 String   selectedImagePath = getRealPathFromURI(selectedImageUri);
 Log.w("Path", "Camera Image Path :" + selectedImagePath);


}
}





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();
                  }
              }


No comments:

Post a Comment