How do I stop XML email attachment translating to HTML in the GMail app

mz_jessikaxo

New Member
I am trying to load a file into my application. The file is a standard KML file and if I load it as a file (for example using dropboxes) it works perfectly. If I send the file via email it transfers fine on my desktop, but if I try with my intent-filter the content is turned into really bad HTML.I created the intent filter and I get my app in the list for preview and download actions on the gmail app:\[code\] <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> <data android:pathPattern=".*..*..*..*..*..*.kml" /> <data android:pathPattern=".*..*..*..*..*.kml" /> <data android:pathPattern=".*..*..*..*.kml" /> <data android:pathPattern=".*..*..*.kml" /> <data android:pathPattern=".*..*.kml" /> <data android:pathPattern=".*.kml" /> </intent-filter>\[/code\]By the way, I tried many different intent-filters, for example a scheme of "content" would not list my app in the download actions... so something there I don't really get.My code in onCreate() for handling the intent is here:\[code\] Intent i = getIntent(); if (i == null) return; Uri u = i.getData(); if (u == null) return; String scheme = u.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { try { Log.i(TAG, "kmlLoader() - reading from ContentResolver"); ContentResolver cr = getContentResolver(); AssetFileDescriptor afd = cr.openAssetFileDescriptor(u, "r"); long length = afd.getLength(); byte[] filedata = http://stackoverflow.com/questions/12426020/new byte[(int) length]; InputStream is = cr.openInputStream(u); if (is == null) return; try { is.read(filedata, 0, (int) length); String x = new String(filedata,"UTF8"); Log.i(TAG, "read " + x.length() + " bytes from ContentResolver"); loadKmlData(x); } catch (IOException e) { Log.i(TAG, "Io exception loading content"); return; } } catch (FileNotFoundException e) { Log.i(TAG, "File not found exception loading content"); return; } } else { // it was a file and this bit works fine\[/code\]If I load though the file bit which works the file is 2207 bytes long. The length reported by the afd above is 5895 bytes. When I get to see the output, it is not the XML I was expecting, but very badly translated HTML. I've read the manual a few times and the ContentResolver is supposed to pass a raw connection to the content, but something is not a RAW as it should be.Any help much appreciated.
 
Back
Top