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卡,因此需要在创建模拟器时配置它。否则,将无法读取或写入文件系统。

相关内容

热门资讯

透视插件!aapoker发牌逻... 透视插件!aapoker发牌逻辑(透视)真的假的(切实是有挂);1、透视插件!aapoker发牌逻辑...
透视教程!aapoker免费透... 透视教程!aapoker免费透视脚本(透视)插件(一直真的有挂);aapoker免费透视脚本辅助器中...
透视了解!aapoker辅助插... 透视了解!aapoker辅助插件工具(透视)免费透视脚本(切实存在有挂);1、aapoker辅助插件...
透视规律!aapoker辅助工... 透视规律!aapoker辅助工具安全吗(透视)万能辅助器(好像是真的有挂)运aapoker辅助工具安...
透视脚本!aapoker真的假... 透视脚本!aapoker真的假的(透视)发牌逻辑(其实是有挂)1、透视脚本!aapoker真的假的(...
透视了解!aapoker如何设... 透视了解!aapoker如何设置胜率(透视)透视脚本(切实是真的有挂)1、aapoker如何设置胜率...
透视教程!aapoker透视插... 透视教程!aapoker透视插件(透视)万能辅助器(本来真的是有挂)1、aapoker透视插件系统规...
透视黑科技!aa poker透... 透视黑科技!aa poker透视软件(透视)插件(都是是有挂);所有人都在同一条线上,像星星一样排成...
透视软件!aapoker透视脚... 透视软件!aapoker透视脚本下载(透视)脚本(切实真的有挂)1、点击下载安装,aapoker透视...
透视辅助!aapoker透视脚... 透视辅助!aapoker透视脚本入口(透视)插件(切实真的有挂)1、金币登录送、破产送、升级送、活动...