2012-07-14 5 views
5

No sé si has visto la asombrosa actualización de Mytrack, pero permite enviar un archivo kml a la aplicación Google Earth y mostrarlo dentro de la aplicación Google (si está instalado, por supuesto).¿Cómo puedo enviar un archivo kml a Google Earth, como MyTracks (código abierto) hacer?

enter image description here

El código fuente está ahí: http://code.google.com/p/mytracks/source/browse/

pero no puedo encontrar la manera de lograr tal cosa.

Creo que he encontrado algo aquí: 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); 

La forma codificada da este código:

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

Pero el código anterior simplemente muestra el camino con el mismo resultado de este código:

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

Mi objetivo es obtener el mismo resultado, con un "juego" pero tonelada.

Respuesta

6

Debe especificar el URI en su archivo KML Y el tipo MIME KML, como se indica a continuación.

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

Esto está actualmente indocumentado, pero estamos intentando arreglar esto.

Asegúrese de utilizar Intent::setDataAndType y no Intent::setData y Intent::setType por separado (cada uno se anula al otro).

"my_track" es una referencia a su ID de marca de posición. La intención extra automáticamente comienza la gira.

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

¿Es posible usar un enlace en lugar de un kml del disco? Algo como esto:

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

Gracias

1

Si el idioma de Android N, no se le permite enviar un archivo: // intención más. Use las instrucciones en android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData(), y agregue la bandera Intent.FLAG_GRANT_READ_URI_PERMISSION.

+0

¿Hubo también un cambio de Android 5 a 6? Mi aplicación puede abrir un archivo KML en Google Earth en Android 5. En Android 6, se abre Google Earth, pero aparentemente no recibió el archivo KML. –

Cuestiones relacionadas