Android 我怎样才能像MyTracks(开源)那样将kml文件发送到Google Earth?

Android 我怎样才能像MyTracks(开源)那样将kml文件发送到Google Earth?,android,android-intent,kml,google-earth,Android,Android Intent,Kml,Google Earth,我不知道你是否看到了Mytrack的惊人更新,但它允许向Google Earth应用程序发送kml文件,并在Google应用程序中显示(当然,如果安装了) 源代码在那里: 但我找不到实现这一目标的方法 我想我在这里发现了一些东西: 硬编码方式给出了以下代码: Intent intent = new Intent() .addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP

我不知道你是否看到了Mytrack的惊人更新,但它允许向Google Earth应用程序发送kml文件,并在Google应用程序中显示(当然,如果安装了)

源代码在那里:

但我找不到实现这一目标的方法

我想我在这里发现了一些东西:

硬编码方式给出了以下代码:

    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);
 Intent mapIntent = new Intent(Intent.ACTION_VIEW); 
    Uri uri1 = Uri.parse("file:///sdcard/test.kml"); 
    mapIntent.setData(uri1); 
    startActivity(Intent.createChooser(mapIntent, "Sample")); 
但上面的代码仅显示与此代码结果相同的路径:

    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);
 Intent mapIntent = new Intent(Intent.ACTION_VIEW); 
    Uri uri1 = Uri.parse("file:///sdcard/test.kml"); 
    mapIntent.setData(uri1); 
    startActivity(Intent.createChooser(mapIntent, "Sample")); 

我的目标是通过“播放”按钮获得相同的结果。

您需要指定KML文件的URI和KML MIME类型,如下所示

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的引用。intent extra会自动启动巡演

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

...

是否可以从磁盘使用链接而不是kml? 大概是这样的:

intent.setDataAndType(Uri.parse(“http://sites.cyclingthealps.com/other/downloads/doc.kml”),“application/vnd.googleearth.kml+xml”)

谢谢


来源:

如果您的目标是安卓N,则不允许再发送文件://intent。使用上的说明,并添加
Intent.FLAG\u GRANT\u READ\u URI\u PERMISSION
FLAG。

是否也将Android 5更改为6?我的应用程序可以在Android 5的Google Earth中打开KML。在Android 6中,Google Earth打开了,但它显然没有收到KML文件?