Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Custom Image Selector not identifing photo location #5015

Closed
mds08011 opened this issue Jul 17, 2022 · 25 comments · Fixed by #5190
Closed

[Bug]: Custom Image Selector not identifing photo location #5015

mds08011 opened this issue Jul 17, 2022 · 25 comments · Fixed by #5190

Comments

@mds08011
Copy link
Contributor

Summary

The "custom picture selector" is not recognizing the locations from my photo's EXIF data. If I upload a photo using the regular file selctor, the app is able to identify the location of the photo from EXIF data. If I select the same photo with the custom selector, I get a "no location found" dialog box.

By "regular selector," I am referring to the button highlighted by a green box in the image below. "Custom selector" is in the red box.

(Not totally sure I have the name correct, but this is the feature I am referring to: #4764)

Steps to reproduce

  1. Select a photo known to have associated location data using the "regular selector". Note whether the app is able to idenfiy the image's location.
  2. Select the same photo using the "custom selector".
  3. The app indicates that no location is found.

Expected behaviour

Expected to identify location from EXIF data.

Actual behaviour

App indicates no location is found for the photo.

Device name

Google Pixel 4a

Android version

Android 12

Commons app version

4.0.1

Device logs

I didn't capture logs but can reproduce if they would be helpful.

Screen-shots

Image selected with custom picker does not identify location:

The same photo via the regular image selector identifies a location:

Would you like to work on the issue?

Prefer not

@mds08011 mds08011 added the bug label Jul 17, 2022
@nicolas-raoul
Copy link
Member

Thanks for reporting!
I have experienced a rather similar problem, always on Pixel 4, and never with my old Samsung somehow. If you have access to other phones, would you mind trying?

Does sharing from Google Photos work? And what about from a third-party gallery app? Thanks!

@mds08011
Copy link
Contributor Author

I don't have another phone easily available but I'll see what I can dig up.

Sharing from Google Photos works without issue, but sharing from a third-party image gallery (Solid Explorer's "SE Image Viewer" in my case) has the same problem identifying image location.

@mds08011
Copy link
Contributor Author

@sivaraam , would you mind trying to reproduce this issue on your OnePlus Nord?

Checking whether image locations are identified when sharing photos from a third-party image gallery and/or using the Custom Photo Selector.

@nicolas-raoul
Copy link
Member

nicolas-raoul commented Aug 6, 2022

From third-party gallery (Simple Gallery, by Simple Mobile Tools), I share to:

  • EXIF Viewer: It shows coordinates
  • Commons app: It tells me "no location found"

Screencast: https://youtu.be/-azE7U-lGgA

Pixel 4, picture taken using stock camera

Then when I share the same picture from the Google Photos app, the Commons app finds the location:
Screenshot_20220806-151942

@sivaraam
Copy link
Member

sivaraam commented Aug 21, 2022

Apologies. I somehow happened to miss the ping here.

@sivaraam , would you mind trying to reproduce this issue on your OnePlus Nord?

Checking whether image locations are identified when sharing photos from a third-party image gallery and/or using the Custom Photo Selector.

Sure. I tried to check but I'm facing a somewhat weird situation. The app doesn't seem to be considering the location information in any of the images I try to upload i.e., I get the "No location found" pop-up in all cases though the image has location information in it. I tried to use regular upload option / custom image selector and sharing to the app from gallery app. All have consistent results.

Not sure why this is happening. I don't remember it being like this before. I'm using v4.0.3.~23c474b06 on OnePlus Nord that runs Android 12. I've checked that the "Location" checkbox is turned on in the "Manage EXIF tags" setting.

@Bongo50
Copy link

Bongo50 commented Aug 26, 2022

I would like to mention that I am also experiencing this issue on my Moto G50 running Android 12. Location works as expected on the "regular" selector but not the custom selector.

@nicolas-raoul
Copy link
Member

I did some experiments using a picture that has location (proved by ExifViewer app).

At presenter.receiveImage(uploadableFile, place) in UploadMediaDetailFragment.java, uploadableFile's file points to /data/user/0/fr.free.nrw.commons/cache/CommonsContributions/9886dd0c-bf3f-41bb-83a6-9aa5eaff20d3.jpg (or similar) which contains 0,0 as EXIF location (downloaded via Device File Explorer then analyzed with exif command line tool)

Using the "normal" picker, at the same breakpoint, uploadableFile's file points to a jpg which contains a real (non-zero) EXIF location.

Both normal picker and custom picker go via receiveInternalSharedItems

The intent is sent by methods called from onPictureReturnedFromCustomSelector whose data argument contains an Image object whose path is /storage/emulated/0/DCIM/Camera/PXL_20220921_005652237.jpg which has correct EXIF coordinates (even for custom picker) as seen by the EXIF tool after download using Android Studio's Device File Explorer.

Anyone willing to help: It could be interesting to check what happened in older versions of the app, in both custom and not (and maybe also in Android 8 where I did not observe this issue).

@nicolas-raoul
Copy link
Member

https://commonsware.com/Q/pages/chap-location-002.html :

"in Android 10, access to [EXIF location] is much more restricted than it had been."

"only option appears to be to get the Uri for each individual image and use ExifInterface"

@nicolas-raoul
Copy link
Member

nicolas-raoul commented Nov 2, 2022

On branch https://github.com/commons-app/apps-android-commons/tree/location-loss I did an experiment following https://developer.android.com/training/data-storage/shared/media#media-location-permission

I added the ACCESS_MEDIA_LOCATION permission to the manifest. I also requested the permission at runtime as it is also required but no permission dialog is shown, apparently it is normal: https://stackoverflow.com/a/74288314/226958.

Then in FilePicker.getFilesFromGalleryPictures I got Intent.getClipData().getItemAt(0).getUri() and passed it to ExifInterface.getLatLong(), unfortunately the result is null for a picture that Google Photos shows has a location.

Any idea what I might be missing?

@sivaraam
Copy link
Member

sivaraam commented Nov 7, 2022

Any idea what I might be missing?

I'm not absolutely sure but maybe you missed the following point mentioned in the article ?

Your app needs to call MediaStore.setRequireOriginal(), supplying the Uri for which you would like the location — this method then returns a decorated Uri that can be used with openInputStream()

@nicolas-raoul
Copy link
Member

@sivaraam you are right! I added setRequireOriginal and now I get Calling uid does not have permission to access picker uri: content://media/picker/0/com.android.providers.media.photopicker/media/1000032383?requireOriginal=1.
If I understand https://issuetracker.google.com/issues/243294058#comment6 correctly, ACTION_PICK_IMAGES not giving EXIF location in "Working as Intended". 😱

We need to also try with the sharing intent and custom picker.

@nicolas-raoul

This comment was marked as off-topic.

@nicolas-raoul

This comment was marked as off-topic.

@Keerthivardhan1
Copy link

Keerthivardhan1 commented Mar 3, 2023

Hello @nicolas-raoul I had goon through this issue , all the helping sites that you have provided in this issue and some other
In : https://commonsware.com/Q/pages/chap-location-002.html
It says that from android 10 image location data had became more restricted
after a lot of research , browsing .
I think one of the solution might be

Using ExifInterface

In the android media package inside the class with name "Classes" we have the class called ** ExifInterface
using this we can extract meta data of the given image file.

getLatLong (float[] output) in the class ExifInterface

Using this method we can find the Geo location where the photo had been taken

Demonstration

ExifInterface exifdata = new ExifInterface();
float[] location = new float[2]; // creating an array to store latt and long values
boolean haslocation = exif.getLatLong( location )

// the function getLatLong ( array ) will return boolean value if Exif tags available it returns true else false

if (haslocation) {
System.out.println("Latitude: " + latLong[0]);
System.out.println("Longitude: " + latLong[1]);
}

I know java programming very well but I am new to android development . I love learning things by doing . I am very much interested in solving this issue. can I solve?
If you feel I am eligible to solve this issue can you please assign this issue to me .
I am very sorry if aim wrong . and Please let me know if I had to learn any thing more before jumping in the code.

for more clarity I would suggest to visit following sites : -
https://developer.android.com/reference/android/media/ExifInterface#getLatLong(float[])
https://stackoverflow.com/questions/56076890/how-to-fetch-the-locationlocation-at-which-image-was-taken-of-selected-image-f

Thank You

@nicolas-raoul
Copy link
Member

@Keerthivardhan1 Thanks for the investigation! Feel free to modify the source code and try. i assign you to the issue, please let us know about your progress every few days. 🙂

@Keerthivardhan1
Copy link

Keerthivardhan1 commented Mar 4, 2023

sure
Thanks a lot @nicolas-raoul . I will give my best to solve this issue.

@Keerthivardhan1
Copy link

Keerthivardhan1 commented Mar 6, 2023

logincc
I tried to setup the project locally its done but when i tried to run the app via USB (connected to my phone )
while I am logging in I am getting this error
weeki


Mobile details : -
Redmi 9A
android version : - 10 QP1A.190711.020

@Keerthivardhan1
Copy link

Keerthivardhan1 commented Mar 6, 2023

So I skipped the process .
after entering into the app it was showing --> " Error Fetching nearby places. Attempt to read from *null Array "
Because : - >
error occurred :
2023-03-06 17:58:36.185 8995-8995/fr.free.nrw.commons.beta D/ExploreMapFragment: Map projection bounds are null
2023-03-06 17:58:36.199 8995-8995/fr.free.nrw.commons.beta D/ExploreMapFragment: java.lang.NullPointerException: Attempt to read from null array
at fr.free.nrw.commons.explore.map.ExploreMapPresenter.getLatLngBounds(ExploreMapPresenter.java:223)
at fr.free.nrw.commons.explore.map.ExploreMapPresenter.updateMapMarkers(ExploreMapPresenter.java:193)
at fr.free.nrw.commons.explore.map.ExploreMapFragment.updateMapMarkers(ExploreMapFragment.java:393)
at fr.free.nrw.commons.explore.map.ExploreMapFragment.lambda$populatePlaces$5$ExploreMapFragment(ExploreMapFragment.java:373)
at fr.free.nrw.commons.explore.map.-$$Lambda$ExploreMapFragment$roHh3jxKNXZ05whErtypW_DhcmQ.accept(Unknown Source:6)
at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:63)


so I started debugging .. these are the following takeaways .

  1. in ---> private LatLngBounds getLatLngBounds(LatLng[] boundaries) ....
    boundaries array is pointing to null

These is the reason why its generating null pointer exception

  1. this is called at
    exploreMapFragmentView.setMapBoundaries(CameraUpdateFactory.newLatLngBounds(- - -getLatLngBounds(explorePlacesInfo.boundaryCoordinates), 50)- - --);

that means : - > explorePlacesInfo.boundaryCoordinates is null
it is failed to update .


right now I am unable to find where it should get updated ? but I will try to find it out . are there any suggestions ?
Your suggestions matters a lot . it will be very helpful .
please let me know if I am wrong . Thank you

@nicolas-raoul
Copy link
Member

@Keerthivardhan1 Make sure the device has internet access. And maybe try to use the prodDebug flavor.

@Keerthivardhan1
Copy link

when we try to upload By "regular selector,"
exif data has the information of location
Screenshot 2023-03-11 005015

but we try to uppload the img from custom selector
there is no geo location
start
Hear :-
exif object == red color
latitude value == blue color
because
exif object is pointing to null ..
so there will be no values of latitude and longitude.

in the path of the normal img selector the imagecoordinates class it is getting the exif object with all the information . so
it is successfully assigning the value of the cordinaties (location ) to latitude and longitude .

Can you please tell me what is the path followed when user clicks the " custom selector " ??? ( even a rough idea or explanation could help me a lot ).
same as that of normal selector or different ?

so that I can know what makes the uploading process of custom selector different from that of normal one . and by this we can know the reason for this issue or exif object to become null .
thank you .

@nicolas-raoul
Copy link
Member

@Keerthivardhan1 Custom selector is highlighted in red in the issue description. To know how the execution paths differ, you will need to execute both in your Android IDE's debugger, and compare.

@Keerthivardhan1
Copy link

Ok , Thanks a lot for giving me this idea @nicolas-raoul

@sivasubramaniamv
Copy link
Contributor

sivasubramaniamv commented Mar 23, 2023

@nicolas-raoul I have quite some experience in building android apps with Kotlin/XML & Kotlin/Compose. I know java but haven't worked with java on an android project. I'm yet to go through the code but first wanted to test the app as a user. I'm in need of images with EXIF data containing location to test & observe the app's behavior.

In the developer workflow guide the 5th point states that anyone can contact the mailing list to obtain good pictures. But I'm new to mailing lists and not sure how to do so. Can you provide me with forward guidance? How do I contact others via the mailing list?

Edit:

I obtained some sample images with EXIF GPS lat/long data from this repository & tested the app. The commons app detected location from pictures picked with the default file picker, built-in custom picker & also 3rd party apps (Realme Gallery app & Z archiver).

But when I uploaded images with no location data, no prompt was shown asking me to enter the data manually.

I've verified the location data of images with this app

Test device
Realme 3 pro

Android Version
11

@sivasubramaniamv
Copy link
Contributor

@nicolas-raoul Can you review my PR?

nicolas-raoul pushed a commit that referenced this issue Mar 31, 2023
@nicolas-raoul
Copy link
Member

GSoC applicants: While this issue was the most representative location loss issue, I suggest working on these ones instead: location-loss

nicolas-raoul pushed a commit that referenced this issue Apr 3, 2023
* feedback dialog: fix black font in dark mode

* LocationPickerActivity: fix light map in dark mode

* Fix #5182 Switch From Mapbox to MapLibre (#5184)

* Fix #5182 Switch From Mapbox to MapLibre

* Fix #5182 Switch From Mapbox to MapLibre - Resolved requestFeature() issue

* Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on two screens

* Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on additional screens

* Fix #5182 Switch From Mapbox to MapLibre - Resolved dark mode issue on notification screen

* Fix #5182 Switch From Mapbox to MapLibre - Test errors

* fix issue #5015 - custom image selector not identifying photo location (#5190)

Co-authored-by: Siva <doodsiva@gmail.com>

* feedback dialog: fix black font in dark mode

* LocationPickerActivity: fix light map in dark mode

* LocationPicker: use predefined style based on device theme

* LocationPickerActivityTest: add additional target exception in catch block

* LocationPickerConstants: remove extra newline introduced

---------

Co-authored-by: Kartikay Kaushik <93285364+kartikaykaushik14@users.noreply.github.com>
Co-authored-by: Siva Subramaniam <112970189+siva-subramaniam-v@users.noreply.github.com>
Co-authored-by: Siva <doodsiva@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants