How to send kml file to Google Earth, for example MyTracks (open source)?

I don’t know if you saw the amazing Mytrack update, but it allows you to send the kml file to the Google Earth application and display it in the Google application (if it is installed, of course).

enter image description here

Source code: http://code.google.com/p/mytracks/source/browse/

but I can’t find a way to achieve this.

I think I found something here: http://code.google.com/r/jshih-mytracks3/source/browse/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveActivity. java? spec = svn5178eb75934b7f0c4c23ec26b7d79a0787de18b8 & r = 5178eb75934b7f0c4c23ec26b7d79a0787de18b8

else if (playTrack) {
        Intent intent = new Intent()
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
            .putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
            .setClassName(GOOGLE_EARTH_PACKAGE, GOOGLE_EARTH_CLASS)
            .setDataAndType(Uri.fromFile(new File(savedPath)), GOOGLE_EARTH_KML_MIME_TYPE);
        startActivity(intent);

The hard-coded way gives this code:

    Intent intent = new Intent()
            .addFlags(
                    Intent.FLAG_ACTIVITY_CLEAR_TOP
                            | Intent.FLAG_ACTIVITY_NEW_TASK)
            .putExtra("com.google.earth.EXTRA.tour_feature_id","tour")
            .setClassName("com.google.earth", "com.google.earth.EarthActivity")
            .setDataAndType(Uri.fromFile(new File("/sdcard/test.kml")),
                    "application/vnd.google-earth.kml+xml");
    startActivity(intent);

But the above code just displays the path with the same result as this code:

 Intent mapIntent = new Intent(Intent.ACTION_VIEW); 
    Uri uri1 = Uri.parse("file:///sdcard/test.kml"); 
    mapIntent.setData(uri1); 
    startActivity(Intent.createChooser(mapIntent, "Sample")); 

- "play".

+5
4

URI KML MML KML .

File file = new File(Environment.getExternalStorageDirectory(), "sample_tour.kml");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.google-earth.kml+xml");
intent.putExtra("com.google.earth.EXTRA.tour_feature_id", "my_track");
startActivity(intent);

, .

Intent::setDataAndType, Intent::setData Intent::setType ( ).

"my_track" - . .

<Placemark id="my_track">
 <gx:Track>
  ...
 </gx:Track>
</Placemark>
+6

kml ? - :

intent.setDataAndType(Uri.parse("http://sites.cyclingthealps.com/other/downloads/doc.kml"), "application/vnd.google-earth.kml+xml");

+3

If you target Android N, you are not allowed to send the file: // intent more. Use the instructions android.os.FileUriExposedException: file: ///storage/emulated/0/test.txt that go beyond the application through Intent.getData () , and add a flag Intent.FLAG_GRANT_READ_URI_PERMISSION.

+1
source
File KML = new File("/sdcard/doc.kml");
Intent i = getPackageManager().getLaunchIntentForPackage("com.google.earth");
i.setDataAndType(Uri.fromFile(KML), "xml");
startActivity(i);

source: http://enladodelbien.blogspot.com/2015/06/kmlkmz-to-google-earth.html

0
source

All Articles