diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java index 6c144436a..b9fe81e8f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java @@ -30,8 +30,8 @@ import com.google.android.apps.mytracks.fragments.ExportDialogFragment; import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller; import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType; import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment; -import com.google.android.apps.mytracks.fragments.PlayMultipleDialogFragment; import com.google.android.apps.mytracks.fragments.MyTracksMapFragment; +import com.google.android.apps.mytracks.fragments.PlayMultipleDialogFragment; import com.google.android.apps.mytracks.fragments.StatsFragment; import com.google.android.apps.mytracks.io.file.TrackFileFormat; import com.google.android.apps.mytracks.io.file.exporter.SaveActivity; @@ -140,9 +140,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity hasPhoto = false; if (id != -1L) { - Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - mediaScanIntent.setData(photoUri); - sendBroadcast(mediaScanIntent); + FileUtils.updateMediaScanner(TrackDetailActivity.this, photoUri); } } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmzTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmzTrackImporter.java index da3318adf..74ef3b591 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmzTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmzTrackImporter.java @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter; import com.google.android.apps.mytracks.util.FileUtils; import android.content.Context; +import android.net.Uri; import android.util.Log; import java.io.ByteArrayInputStream; @@ -184,12 +185,15 @@ public class KmzTrackImporter implements TrackImporter { File dir = FileUtils.getPhotoDir(importTrackId); FileUtils.ensureDirectoryExists(dir); - fileOutputStream = new FileOutputStream(new File(dir, fileName)); + File file = new File(dir, fileName); + fileOutputStream = new FileOutputStream(file); byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((count = zipInputStream.read(buffer)) != -1) { fileOutputStream.write(buffer, 0, count); } + + FileUtils.updateMediaScanner(context, Uri.fromFile(file)); } finally { if (fileOutputStream != null) { fileOutputStream.close(); diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/util/FileUtils.java b/MyTracksLib/src/com/google/android/apps/mytracks/util/FileUtils.java index ea1b7cee8..cd88d3d6c 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/util/FileUtils.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/util/FileUtils.java @@ -15,6 +15,9 @@ */ package com.google.android.apps.mytracks.util; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.os.Environment; import java.io.File; @@ -173,6 +176,12 @@ public class FileUtils { } return fileName.substring(index + 1); } + + public static void updateMediaScanner(Context context, Uri uri) { + Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + mediaScanIntent.setData(uri); + context.sendBroadcast(mediaScanIntent); + } /** * Builds a filename with the given base and the given extension, possibly