java - ExifInterface Latitude/Longitude return null - Android -


good afternoon everyone,

i'm developing simple app android that's suppose picture gallery, displays , show coordinates in textview (latitude , longitude). have exifinterface objext, tags (such tag_gps_latitude , tag_gps_longitude) return null. i've tried many different solutions found on stackoverflow none of them worked, thought of making new question showing code.

mainactivity.java:

  public class mainactivity extends appcompatactivity {      private static int result_load_image = 1;     textview textview;     imageview imageview;     uri imguri;     string realpath;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         textview = (textview) findviewbyid(r.id.txtview);         imageview = (imageview) findviewbyid(r.id.imgview);         button buttonloadimage = (button) findviewbyid(r.id.buttonloadpicture);         buttonloadimage.setonclicklistener(new view.onclicklistener(){             @override             public void onclick(view arg0){                 opengallery(arg0);             }         });     }      public void opengallery(view view){         intent = new intent(intent.action_pick, mediastore.images.media.external_content_uri);         startactivityforresult(i, result_load_image);     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data){          super.onactivityresult(requestcode, resultcode, data);          if(requestcode == result_load_image && resultcode == result_ok){             imguri = data.getdata();             imageview.setimageuri(imguri);             realpath = getrealpathfromuri(this, imguri);             try {                 exifinterface ei = new exifinterface(realpath);                 textview.append("latitude: " + ei.getattribute(exifinterface.tag_gps_latitude) + " longitude: " + ei.getattribute(exifinterface.tag_gps_longitude));              } catch (ioexception e) {                 e.printstacktrace();             }          }     }      public string getrealpathfromuri(context context, uri contenturi) {         cursor cursor = null;         try {             string[] proj = { mediastore.images.media.data };             cursor = context.getcontentresolver().query(contenturi,  proj, null, null, null);             int column_index = cursor.getcolumnindexorthrow(mediastore.images.media.data);             cursor.movetofirst();             return cursor.getstring(column_index);         } {             if (cursor != null) {                 cursor.close();             }         }     } } 

thank you.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -