无法打开文件。可能不是有效的磁贴包

时间:2015-10-22 11:13:37

标签: android arcgis

我正在关注this sample,并且在运行时,我收到此错误:

E/ArcGIS: java.lang.RuntimeException:Internal error exception - Failed to open file. May not be a valid tile package.

这是失败的地方:

final String extern = Environment.getExternalStorageDirectory().getPath();
final String tpkPath = "/ArcGIS/samples/OfflineRouting/SanDiego.tpk";
TiledLayer mTileLayer = new ArcGISLocalTiledLayer(extern + tpkPath);
GraphicsLayer mGraphicsLayer = new GraphicsLayer(GraphicsLayer.RenderingMode.DYNAMIC);

为什么看不到我的文件?我该如何解决?

2 个答案:

答案 0 :(得分:2)

根据我的经验,ArcGISLocalTiledLayer需要文件URL而不是文件路径。所以试试这个:

TiledLayer mTileLayer = new ArcGISLocalTiledLayer("file://" + extern + tpkPath);

这样你就传递了file:///storage/ArcGIS/samples/OfflineRouting/SanDiego.tpk,如果该文件存在,并且你的应用已经请求访问AndroidManifest.xml中的外部存储,那么它应该有效:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

答案 1 :(得分:0)

我用了这个SDK

  implementation 'com.esri.arcgisruntime:arcgis-android:100.5.0'

,代码是

       mMapView = findViewById(R.id.mapView);
   filename = this.getResources().getString(R.string.local_tpk);
   //        We have tpk file in this path
   File storageDir = new File(Environment.getExternalStorageDirectory(), "TPK");
   // create the url
   String base = storageDir + File.separator + filename;

   ArcGISTiledLayer tiledLayerBaseMap = new ArcGISTiledLayer(base);
   // set tiled layer as basemap
   Basemap basemap = new Basemap(tiledLayerBaseMap);
   // create a map with the basemap
   ArcGISMap map = new ArcGISMap(basemap);
   // set the map to be displayed in this view
   mMapView.setMap(map);