This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
MapSnapshotter.ErrorHandler not called on second attempt #668
Open
Description
when the phone is offline, if an activity attempts to create a static image using MapSnapshotter, MapSnapshotter.ErrorHandler is called with the error message,
loading style failed: Unable to resolve host "api.mapbox.com": No address associated with hostname
However when the activity attempts to create another static image again, MapSnapshotter.ErrorHandler is never called.
Expected Result
MapSnapshotter.ErrorHandler should be called indicating the error message whenever static image is generated.
SDK Version: android-v9.5.2
I have modified Mapbox Demo app SnapshotShareActivity to illustrate the problem. See the modified code snippet below
Steps to reproduce
- Clear the app cache/storage from Settings
- Turn off all network access.
- Launch Mapbox demo
- Select "Image generation" from the menu
- Tap on "Share snapshot image"
- MapSnapshotter.ErrorHandler.onError will be called with an error message
- Return to previous screen
- Tap on "Share snapshot image". MapSnapshotter.ErrorHandler.onError is NOT called.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_snapshot_share);
cameraFab = findViewById(R.id.camera_share_snapshot_image_fab);
cameraFab.setImageResource(R.drawable.ic_camera);
hasStartedSnapshotGeneration = false;
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(new LatLng(0, 0));
builder.include(new LatLng(0, 20));
startSnapShot(builder.build(), 300, 300);
}
private void startSnapShot(LatLngBounds latLngBounds, int height, int width) {
// Initialize snapshotter with map dimensions and given bounds
MapSnapshotter.Options options =
new MapSnapshotter.Options(width, height)
.withRegion(latLngBounds)
.withStyle(Style.MAPBOX_STREETS);
mapSnapshotter = new MapSnapshotter(SnapshotShareActivity.this, options);
mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(MapSnapshot snapshot) {
Bitmap bitmapOfMapSnapshotImage = snapshot.getBitmap();
Log.d(SnapshotShareActivity.class.getSimpleName(), "Snapshotted");
}
}, new MapSnapshotter.ErrorHandler() {
@Override
public void onError(String error) {
Log.d(SnapshotShareActivity.class.getSimpleName(), "Snapshot error: " + error);
}
});
}