Jak mogę wysłać plik kml do Google Earth, tak jak MyTracks (open source) zrobić?

Nie wiem, czy widziałeś niesamowitą aktualizację Mytrack, ale pozwala ona wysłać plik kml do aplikacji Google Earth i wyświetlić go wewnątrz aplikacji Google (jeśli jest zainstalowany, oczywiście).

Tutaj wpisz opis obrazka

Jest tam kod źródłowy: http://code.google.com/p/mytracks/source/browse/

Ale nie mogę znaleźć sposobu, by coś takiego osiągnąć.

Myślę, że znalazłem coś tutaj: 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);

Hardcoded sposób daje ten kod:

    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);

Ale powyższy kod po prostu wyświetla ścieżkę z takim samym wynikiem jak ten kod:

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

Moim celem jest uzyskanie tego samego wyniku za pomocą przycisku "play".

Author: JasonM1, 2012-07-14

4 answers

MUSISZ PODAĆ URI do pliku KML i typ MIME KML, w następujący sposób.

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);
To jest obecnie nieudokumentowane, ale chcemy to naprawić.

Upewnij się, że używasz Intent::setDataAndType, a nie Intent::setData i Intent::setType oddzielnie (każde z nich zastępuje drugie).

"my_track" jest odniesieniem do twojego Identyfikatora znacznika. Intent extra automatycznie rozpoczyna trasę.

<Placemark id="my_track">
 <gx:Track>
  ...
 </gx:Track>
</Placemark>
 6
Author: saxman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-27 22:19:15

Czy można użyć linku zamiast kml z dysku? Coś takiego:

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

Thanks

 3
Author: Dennis Wegewijs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-05 20:46:35

Jeśli celujesz w Androida N, nie możesz już wysyłać pliku: / / intent. Użyj instrukcji na Androidzie .os.FileUriExposedException: file: / / / storage/emulated/0 / test.txt ujawnione poza app poprzez Intent.getData () i dodać znacznik Intent.FLAG_GRANT_READ_URI_PERMISSION.

 2
Author: rockgecko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:53:49
File KML = new File("/sdcard/doc.kml");
Intent i = getPackageManager().getLaunchIntentForPackage("com.google.earth");
i.setDataAndType(Uri.fromFile(KML), "xml");
startActivity(i);

Źródło: http://enladodelbien.blogspot.com/2015/06/kmlkmz-to-google-earth.html

 0
Author: Mike Brian Olivera,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-03 04:12:26