aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorStephan Merker <merker.stephan@googlemail.com>2012-01-15 22:34:34 +0100
committerStephan Merker <merker.stephan@googlemail.com>2012-01-15 22:34:34 +0100
commite711c5f8211bf7bce1e1f0598478f0d1d49d866f (patch)
tree423ee52d400c1cc6e03defd4278a42e22dd4117d /main/src
parentcf84dafad27dd8e0f9e9ed5058e057a2198ead77 (diff)
downloadcgeo-e711c5f8211bf7bce1e1f0598478f0d1d49d866f.zip
cgeo-e711c5f8211bf7bce1e1f0598478f0d1d49d866f.tar.gz
cgeo-e711c5f8211bf7bce1e1f0598478f0d1d49d866f.tar.bz2
support more mime types for importing zipped PQs
see issue #967
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/files/GPXImporter.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java
index e7853f0..7ee05ff 100644
--- a/main/src/cgeo/geocaching/files/GPXImporter.java
+++ b/main/src/cgeo/geocaching/files/GPXImporter.java
@@ -26,8 +26,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -46,6 +48,9 @@ public class GPXImporter {
public static final String ZIP_FILE_EXTENSION = ".zip";
public static final String WAYPOINTS_FILE_SUFFIX_AND_EXTENSION = "-wpts.gpx";
+ private static final List<String> GPX_MIME_TYPES = Arrays.asList(new String[] { "text/xml", "application/xml" });
+ private static final List<String> ZIP_MIME_TYPES = Arrays.asList(new String[] { "application/zip", "application/x-compressed", "application/x-zip-compressed", "application/x-zip", "application/octet-stream" });
+
private Progress progress = new Progress();
private Resources res;
@@ -85,19 +90,25 @@ public class GPXImporter {
final Uri uri = intent.getData();
String mimeType = intent.getType();
- // if mimetype can't be determined (e.g. for emulators email app), use a default
+ // if mimetype can't be determined (e.g. for emulators email app), derive it from uri file extension
// contentResolver.getType(uri) doesn't help but throws exception for emulators email app
// Permission Denial: reading com.android.email.provider.EmailProvider uri
// Google search says: there is no solution for this problem
- // TODO: check if problem occurs with gmail as well
+ // Gmail doesn't work at all, see #967
if (mimeType == null) {
- mimeType = "application/zip";
+ if (StringUtils.endsWithIgnoreCase(uri.getPath(), GPX_FILE_EXTENSION)) {
+ mimeType = "application/xml";
+ } else {
+ // if we can't determine a better type, default to zip import
+ // emulator email sends e.g. content://com.android.email.attachmentprovider/1/1/RAW, mimetype=null
+ mimeType = "application/zip";
+ }
}
Log.i(Settings.tag, "importGPX: " + uri + ", mimetype=" + mimeType);
- if (StringUtils.equalsIgnoreCase("text/xml", mimeType) || StringUtils.equalsIgnoreCase("application/xml", mimeType)) {
+ if (GPX_MIME_TYPES.contains(mimeType)) {
new ImportGpxAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
- } else if (StringUtils.equalsIgnoreCase("application/zip", mimeType)) {
+ } else if (ZIP_MIME_TYPES.contains(mimeType)) {
new ImportGpxZipAttachmentThread(uri, contentResolver, listId, importStepHandler, progressHandler).start();
} else {
importFinished();