Tuesday 15 January 2013

Retrieving Image Path in android studio -


I'm working on Android apps There is a functionality in which the captured picture should be displayed on the screen and I have to get that image path so that I can send that image to the server.

Here's my code:

  Private Zero Lefoto (see V) {intention intended = new intent (mediastore.action_IMUNNCNPS); Intent.putExtra (MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString ()); Photo = new file (environment GateInstinstoraz Public Directory (environment. DIRECTORY_PICTURES), "picture.jpg"); ImageUri = Uri.fromFile (photo); Intent.putExtra (MediaStore.EXTRA_OUTPUT, imageUri); StartActivityForResult (intent, TAKE_PICTURE); }  


  public inactive onActivityResult (int requestcode, desirable result code, intent data) {super.onActivityResult (requestCode, resultCode, data); If (requestcode == TAKE_PICTURE) {if (resultCode == activity. RESULT_OK) {Ure selected image = image URI; GetActivity () GetContentResolver () Inform (selected image, blank); ImageView imageview = (ImageView) getActivity () FindViewById (R.id.imageView); ContentResolver cr = getActivity () GetContentResolver (); Try {// adding an image attachment to the email string} filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getActivity (). GetContentResolver () Query (selected image, filePathColumn, blank, empty, empty); Cursor.moveToFirst (); Columnindex = cursor.just column index (filespace column [0]); Attachment file = cursor.getstring (column index); Logs. ("Attachment Path:", Attachment File); URI = Uri Prs ("file: //" + attachment file); Cursor.close (); Bitmap = MediaStore.images.Media.getBitmap (CR, Selected Image); Imageview.setImageBitmap (bitmap); Toast. MakeActivity (), "Photoshoot complete", Toast.LnnGH_Leng). Show (); } Hold (exception e) {toast. MakeActivity (), "could not be completed, please try again.", Toast. LNNGHHORT); Logs. E ("error", e.ostustring ()); }  

The format of the path is currently:

File: ///storage/emulated/0/Pictures/pictures.jpg < / P>

I want the path of the format: content: // media / external / images / media / 34826

when I try to change

URI selected image = image Yuri;

By

selected URI Image = data.getData ();

For the necessary content, "data" includes a zero value.


No comments:

Post a Comment