Thanks for the reply. It works with this URL and the credential supplied. I didn't realize the ArcGIS online service does not have exportTiles method
Perhaps the developers for runtime SDK can make more meaningful error message than "java.util.concurrent.ExecutionException: com.esri.arcgisruntime.ArcGISRuntimeException: Cannot call this method in this context"
For others who faced the same problem, here's the snippet in Kotlin
val env = viewToExtent() // Similar to the sample
val minScale = 10000.0 // 1 : 10000
val maxScale = 1000.0 // 1 : 1000. Make sure maxScale < minScale
val filepath = "sdcard/mymap/test.tpk" // Path to your map file. Make sure the directories are already created
val url = "https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Topo_Map/MapServer/"
val exportTask = ExportTileCacheTask(url)
// Set the credentials, because the tiledbasemap service requires auth
exportTask.setCredential(UserCredential("<your-username>", "<your-password>"))
exportTask.addDoneLoadingListener{
val future = exportTask.createDefaultExportTileCacheParametersAsync(env, minScale, maxScale)
future.addDoneListener {
// Get parameter
val params = future.get()
// Create export job with the given param and filepath. The actual download and export happen here
val exportJob = exportTask.exportTileCacheAsync(params, filepath)
// If you care about the status of your job
exportJob.addJobChangedListener { Log.i("INFO", "jobInfo: ${exportJob.messages.last().message}") }
// When the job is done
exportJob.addJobDoneListener {
val result = job.result
if (result != null) {
// Success. The tpk file is saved to the supplied file path. The result contains the info about the TPK file
} else {
// Failed. Perhaps due to the above error, or the tpk size is too big (Dunno the exact limit)
}
}
// Start the job
exportJob.start()
}
}
exportTask.loadAsync()
Also, another bit of a problem. I noticed that the Envelope class is not serialized (or is it?).
So, is it not possible to pass the Envelope inside an Intent, to be sent to a Service / another Activity?
Thanks again for the quick response,
Jason