java - How to convert URI to real path in marshmallow? -


i have image uri , want convert uri real path. i've looked @ lot of of answers none worked me. i'm using marshmallow 6.0.1. image uri content://com.android.providers.media.documents/document/image%3a52530.

code:

   sendimagefromfolder.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view view) {                      intent intent = new intent();                     intent.settype("image/*");                     intent.putextra(intent.extra_allow_multiple, true);                     intent.setaction(intent.action_get_content);                     startactivityforresult(intent.createchooser(intent,"select picture"), 1);                  }             });       protected void onactivityresult(int requestcode, int resultcode, intent data) {             super.onactivityresult(requestcode, resultcode, data);       if(requestcode==1) {           uri uri = data.getdata();//how convert uri real path .     }      } 

a uri not file. uri not have represent file on filesystem can access. uri might point content is:

  • stored on removable storage, cannot access
  • stored on internal storage of app, cannot access
  • stored in encrypted form, contentprovider needs decrypt it
  • stored in blob column of sqlite database, contentprovider needs load , serve it
  • stored in "the cloud", contentprovider needs download it
  • generated on fly, way web page is
  • and on

you can use contentresolver , openinputstream() inputstream on content represented uri. can create fileoutputstream on file control. and, can use java i/o copy inputstream outputstream, making own copy of content in file control.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -