Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Adding try/catch to SnapshotNotificationActivity to catch IllegalStateException #1236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
});
}
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/activity_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<!--Tap on map instruction for toast-->
<string name="tap_on_map_instruction">Tap anywhere on the map</string>
<string name="tap_on_map_for_notification">Tap on map to get a notification with map image</string>
<string name="snapshotter_was_already_started">Snapshotter was already started</string>

<string name="san_francisco">San Francisco</string>
<string name="los_angeles">Los Angeles</string>
Expand Down