diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotNotificationActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotNotificationActivity.java index 96f76611d..5e68d4445 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotNotificationActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/snapshot/SnapshotNotificationActivity.java @@ -8,6 +8,7 @@ import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; +import android.widget.Toast; import com.mapbox.mapboxandroiddemo.MainActivity; import com.mapbox.mapboxandroiddemo.R; @@ -24,6 +25,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationCompat; +import timber.log.Timber; import static android.app.PendingIntent.getActivity; @@ -102,12 +104,18 @@ public void onStyleLoaded(@NonNull Style style) { mapSnapshotter.setSize(width, height); mapSnapshotter.setRegion(latLngBounds); } - mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() { - @Override - public void onSnapshotReady(MapSnapshot snapshot) { - createNotification(snapshot.getBitmap()); - } - }); + try { + mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() { + @Override + public void onSnapshotReady(MapSnapshot snapshot) { + createNotification(snapshot.getBitmap()); + } + }); + } catch (IllegalStateException exception) { + Timber.d(exception); + Toast.makeText(SnapshotNotificationActivity.this, + R.string.snapshotter_was_already_started, Toast.LENGTH_SHORT).show(); + } } }); } diff --git a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml index 88e9a26f7..aa1e6a636 100644 --- a/MapboxAndroidDemo/src/main/res/values/activity_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/activity_strings.xml @@ -121,6 +121,7 @@ Tap anywhere on the map Tap on map to get a notification with map image + Snapshotter was already started San Francisco Los Angeles