Android模拟器无法添加KML文件
创始人
2024-10-09 06:31:12
0

要在Android模拟器中添加KML文件,需要在代码中设置对应的权限。首先,需要在AndroidManifest.xml文件中添加以下权限:



然后,在文件选择器中调用以下代码:

Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"application/vnd.google-earth.kml+xml", "application/vnd.google-earth.kmz"});
startActivityForResult(intent, fileSelectorRequestCode);

在onActivityResult方法中,获取选中文件的URI并用Google Maps API解析它:

if (requestCode == fileSelectorRequestCode && resultCode == RESULT_OK) {
    Uri uri = data.getData();
    try {
        InputStream inputStream = getContentResolver().openInputStream(uri);
        KmlLayer kmlLayer = new KmlLayer(mMap, inputStream, getApplicationContext());
        kmlLayer.addLayerToMap();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }
}

注意:在Android模拟器中,默认情况下没有SD卡,因此需要在创建模拟器时配置它。否则,将无法读取或写入文件系统。

相关内容

热门资讯

一分钟教你!wepoker手机... 一分钟教你!wepoker手机版透视脚本,wepoker辅助器激活码,新版2025教程(有挂方法)是...
分享一款!wepoker有没有... 分享一款!wepoker有没有机器人,wepoker透视是真的吗,透明教程(有挂透明)是一款可以让一...
终于知道!wepoker私人局... 终于知道!wepoker私人局辅助器怎么用,哈糖大菠萝能开挂吗,揭秘教程(有挂技巧)1、玩家可以在w...
记者揭秘!德普之星辅助工具如何... 记者揭秘!德普之星辅助工具如何设置,hhpoker德州真的假的,揭秘教程(有挂软件)1、很好的工具软...
盘点一款!pokemmo手机脚... 盘点一款!pokemmo手机脚本辅助器,wepoker有辅助功能吗,解密教程(有挂辅助);建议优先通...
解密关于!wepoker辅助是... 1、解密关于!wepoker辅助是真的吗,wpk辅助器,AI教程(有挂技巧)。2、wepoker辅助...
推荐攻略!we-poker辅助... 推荐攻略!we-poker辅助,hhpoker有后台操作吗,切实教程(有挂辅助)关于hhpoker有...
每日必备!pokemmo手机版... 每日必备!pokemmo手机版透视脚本,wpk辅助器,透明教程(有挂神器);建议优先通过pokemm...
一分钟揭秘!hhpoker是正... 《一分钟揭秘!hhpoker是正规的吗,wepoker怎么挂底牌,玩家教你(有挂透明)》 hhpok...
我来教教大家!wepoker看... 我来教教大家!wepoker看底牌,约局吧德州可以透视吗,揭秘攻略(有挂透视)1、不需要AI权限,帮...