paktan / osmtracker-android

Automatically exported from code.google.com/p/osmtracker-android
GNU General Public License v3.0
0 stars 0 forks source link

Exported tracks are not visible over MTP until a media scan is performed #261

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a track with some photos and voice notes.
2. Export the track.
3. Connect phone to your computer.

What is the expected output? What do you see instead?
I would expect a folder with the GPX file and all attachments. Instead, the 
folder contains only the GPX file. If I trigger a media scan (using Android's 
Developer Tools), all the files are there after the scan completes.

What version of the product are you using (See "About" screen)?
0.6.9 (downloaded from F-Droid)

Make/model of your device, and Android version?
OnePlus One (A0001/bacon), Cyanogenmod 11.0m11 (Android 4.4.4)

Please provide any additional information below.
This only affects MTP devices. My old Nexus S (which exposed its file system as 
USB mass storage) did not have this issue. I reported this as a bug in 
Cyanogenmod and was told that apps are expected to call 
MediaScannerConnection#scanFile 
http://developer.android.com/reference/android/media/MediaScannerConnection.html
#scanFile(java.lang.String, java.lang.String) after creating a new file. 
Apparently OSMTracker for Android is not doing this for all files.

Original issue reported on code.google.com by mich...@vonglasow.com on 18 Feb 2015 at 6:03

GoogleCodeExporter commented 9 years ago
Hi, we don't indeed call this function, but we do something that's supposed to 
be similar: 
https://github.com/nguillaumin/osmtracker-android/blob/1e404a41ae241b02603643ddf
bf11230cddab305/src/me/guillaumin/android/osmtracker/gpx/ExportTrackTask.java#L2
46

As far as I know it has been working well so far, at least on official Android 
devices. Could this be something specific to CyanogenMod?

Original comment by nicolas@guillaumin.me on 19 Feb 2015 at 8:53

GoogleCodeExporter commented 9 years ago
Taking a brief look at the code, I see you trigger a media scan only for the 
GPX file, not for the media files. The way you do it is similar and apparently 
works on CM, and this also explains why I am seeing the GPX file but not the 
media files.

I haven't looked into the API calls in detail, but if the API supports scanning 
of entire directories rather than single files, that would be an option.

Original comment by mich...@vonglasow.com on 19 Feb 2015 at 5:29

GoogleCodeExporter commented 9 years ago
Ah I see, fair enough. I think triggering an intent on 
FileSystemUtils.copyFile() would do the trick: 
https://github.com/nguillaumin/osmtracker-android/blob/master/src/me/guillaumin/
android/osmtracker/util/FileSystemUtils.java#L29

You seem to be on top of things, how about a pull request for this one? :)

Original comment by nicolas@guillaumin.me on 20 Feb 2015 at 8:02

GoogleCodeExporter commented 9 years ago
OK, just forked the project, I'll let you know when I have something.

Original comment by mich...@vonglasow.com on 23 Feb 2015 at 10:22

GoogleCodeExporter commented 9 years ago
Just issued pull request #44.

I implemented this a bit differently from how you suggested it: Apparently, as 
of Android 4.4, there is no longer a way to trigger a scan of an entire 
directory (source: http://stackoverflow.com/a/25086535/2703209).

However, there is a way to pass an array of files to scan – if you use the 
MediaScannerConnection call. This is what I did instead of the intent. I'm not 
sure about performance impact, but I think it's better to pass the entire list 
of files to be scanned in one go rather than trigger a separate scan for each 
file. In the worst of all cases, it'll do neither harm nor good.

Little side effect: when exporting to a non-empty folder, existing files in 
that folder will get scanned as well – don't think that's an issue, though.

Ran a brief trial and all files (GPX and voice notes) were visible via MTP 
instantly.

Original comment by mich...@vonglasow.com on 25 Feb 2015 at 10:48

GoogleCodeExporter commented 9 years ago
As per your suggestions regarding my pull request, I tried to add a media 
scanner call to copyFile(). However, this requires a Context (apparently on 
Android I can't even scratch my back without a Context), and I have no idea how 
I can get a Conext inside copyFile() other than by adding a context argument to 
every method the call hierarchy.

Any other ideas?

Original comment by mich...@vonglasow.com on 10 Mar 2015 at 10:37

GoogleCodeExporter commented 9 years ago
Ah, good point, I haven't thought of that. Well I guess then doing it on the 
GPX export task is probably good enough... If you re-open your request I'll 
merge it, thanks!

Original comment by nicolas@guillaumin.me on 11 Mar 2015 at 8:24

GoogleCodeExporter commented 9 years ago
Thanks, I merged your code so it'll be available in the next release.

Original comment by nicolas@guillaumin.me on 18 Mar 2015 at 10:35