Select to view content in your preferred language

Loading a TPK file from assets folder

1128
2
11-29-2016 11:03 PM
JasonChristian
Emerging Contributor

Hi,

Suppose that I have a very small (1-2MBs) TPK file that I want to package along with the released APK, how can I reference it from raw or assets folder? What string should I pass for the ArcGISLocalTiledLayer's constructor to display it on to the map?

0 Kudos
2 Replies
JinYingMin1
Deactivated User

Hi,

Do you know the way for use the tpk on android external storage?

You can copy this tpk from asset to external folder and after use as tile layer.

be satisfied?

0 Kudos
BrahimDiaz
Deactivated User

To package a small TPK file (Tile Package) with your Android app and reference it for use with ArcGISLocalTiledLayer, you need to follow these steps:

1. **Place the TPK File in the Assets Folder:**
- Copy your TPK file to the `assets` folder of your Android project. If the `assets` folder doesn't exist, create it under `src/main/`.

2. **Reference the TPK File in Code:**
- Use the `AssetManager` to access the TPK file from the assets folder.

3. **Use the TPK File with ArcGISLocalTiledLayer:**
- You'll use the path to the TPK file relative to the `assets` folder to create an `ArcGISLocalTiledLayer`.

Here's a basic example of how to do this in your Android code:

```java
// Import necessary ArcGIS classes
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.ArcGISLocalTiledLayer;
import com.esri.arcgisruntime.mapping.Basemap;

// Inside your Activity or Fragment
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize the MapView
MapView mapView = findViewById(R.id.mapView);

// Load the TPK file from the assets folder
String tpkPath = "file:///android_asset/your_tile_package.tpk"; // Replace with your TPK file name

// Create the ArcGISLocalTiledLayer using the TPK file path
ArcGISLocalTiledLayer tiledLayer = new ArcGISLocalTiledLayer(tpkPath);

// Create an ArcGISMap and set the tiled layer as the base map
ArcGISMap map = new ArcGISMap(new Basemap(tiledLayer));

// Set the map to the MapView
mapView.setMap(map);
}

@Override
protected void onPause() {
super.onPause();
mapView.pause();
}

@Override
protected void onResume() {
super.onResume();
mapView.resume();
}

@Override
protected void onDestroy() {
super.onDestroy();
mapView.dispose();
}
```

### Key Points:
- **Asset Path:** Use `"file:///android_asset/your_tile_package.tpk"` to reference the file from the assets folder.
- **ArcGISLocalTiledLayer Constructor:** The constructor takes the path to the TPK file as a string.

Make sure you have the necessary permissions and that your project is set up to include the ArcGIS Runtime SDK for Android. Also, ensure the TPK file is correctly named and located in the `assets` folder. 

0 Kudos