|
| 1 | +package com.codenameone.examples.hellocodenameone.tests; |
| 2 | + |
| 3 | +import com.codename1.notifications.LocalNotification; |
| 4 | +import com.codename1.ui.Display; |
| 5 | +import com.codename1.ui.util.UITimer; |
| 6 | + |
| 7 | +public class LocalNotificationTest extends BaseTest { |
| 8 | + @Override |
| 9 | + public boolean shouldTakeScreenshot() { |
| 10 | + return false; |
| 11 | + } |
| 12 | + |
| 13 | + @Override |
| 14 | + public boolean runTest() throws Exception { |
| 15 | + LocalNotification n1 = new LocalNotification(); |
| 16 | + n1.setId("test-notification-1"); |
| 17 | + n1.setAlertTitle("Test Notification 1"); |
| 18 | + n1.setAlertBody("This is a test notification"); |
| 19 | + Display.getInstance().scheduleLocalNotification(n1, System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE); |
| 20 | + |
| 21 | + LocalNotification n2 = new LocalNotification(); |
| 22 | + n2.setId("test-notification-2"); |
| 23 | + n2.setAlertTitle("Test Notification 2"); |
| 24 | + n2.setAlertBody("This is a repeating notification"); |
| 25 | + Display.getInstance().scheduleLocalNotification(n2, System.currentTimeMillis() + 2000, LocalNotification.REPEAT_MINUTE); |
| 26 | + |
| 27 | + LocalNotification n3 = new LocalNotification(); |
| 28 | + n3.setId("test-notification-3"); |
| 29 | + n3.setAlertTitle("Test Notification 3"); |
| 30 | + n3.setAlertBody("This is a notification with badge"); |
| 31 | + n3.setBadgeNumber(5); |
| 32 | + Display.getInstance().scheduleLocalNotification(n3, System.currentTimeMillis() + 3000, LocalNotification.REPEAT_NONE); |
| 33 | + |
| 34 | + UITimer.timer(4000, false, () -> { |
| 35 | + Display.getInstance().cancelLocalNotification("test-notification-1"); |
| 36 | + Display.getInstance().cancelLocalNotification("test-notification-2"); |
| 37 | + Display.getInstance().cancelLocalNotification("test-notification-3"); |
| 38 | + done(); |
| 39 | + }); |
| 40 | + |
| 41 | + return true; |
| 42 | + } |
| 43 | +} |
0 commit comments