8 private NavigineSdk sdk;
9 private LocationManager locationManager;
10 private NotificationManager notificationManager;
11 private NotificationListener notificationListener;
15 setupNotificationListener();
21 private void initializeSdk() {
25 sdk = NavigineSdk.getInstance();
30 sdk.setUserHash(
"USER-HASH-HERE");
35 sdk.setServer(
"https://custom.navigine.com");
40 locationManager = sdk.getLocationManager();
45 notificationManager = sdk.getNotificationManager(locationManager);
48 if (locationManager !=
null && notificationManager !=
null) {
49 System.out.println(
"LocationManager and NotificationManager successfully initialized");
51 }
catch (Exception e) {
52 System.err.println(
"Error initializing SDK: " + e.getMessage());
59 private void setupNotificationListener() {
60 notificationListener =
new NotificationListener() {
63 public void onNotificationLoaded(Notification notification) {
64 System.out.println(
"Notification loaded");
71 public void onNotificationFailed(java.lang.Error error) {
72 System.out.println(
"Notification failed: " + error.getMessage());
83 if (notificationManager ==
null) {
84 System.err.println(
"NotificationManager not initialized");
90 notificationManager.addNotificationListener(notificationListener);
91 System.out.println(
"Added notification listener");
98 }
catch (InterruptedException e) {
99 Thread.currentThread().interrupt();
104 notificationManager.removeNotificationListener(notificationListener);
105 System.out.println(
"Removed notification listener");
114 if (notification ==
null) {
115 System.err.println(
"Notification is null");
121 int id = notification.getId();
122 System.out.println(
"Notification ID: " +
id);
127 String title = notification.getTitle();
128 System.out.println(
"Notification title: " + title);
133 String content = notification.getContent();
134 System.out.println(
"Notification content: " + content);
139 String imageUrl = notification.getImageUrl();
140 if (imageUrl !=
null && !imageUrl.isEmpty()) {
141 System.out.println(
"Notification image URL: " + imageUrl);
143 System.out.println(
"Notification has no image URL");
148 processNotification(notification);
155 System.out.println(
"Handling notification error:");
156 System.out.println(
" Error message: " + error.getMessage());
157 System.out.println(
" Error type: " + error.getClass().getSimpleName());
160 handleNotificationError(error);
175 System.out.println(
"=== NotificationManager Example ===");
182 }
catch (InterruptedException e) {
183 Thread.currentThread().interrupt();
187 System.out.println(
"=== Example completed ===");
193 public static void main(String[] args) {