Я хочу добавить слушателя к локальному уведомлению, поэтому, когда пользователь нажимает на уведомление, открывается браузер, это мой код:
public class MyApplication {
private Form current;
private Resources theme;
Form hi;
Form web;
EncodedImage ei;
Image img;
String url = "https://d1fmx1rbmqrxrr.cloudfront.net/cnet/optim/i/edit/2019/04/eso1644bsmall__w770.jpg";
public void init(Object context) {
// use two network threads instead of one
updateNetworkThreadCount(2);
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature
Log.bindCrashProtection(true);
addNetworkErrorListener(err -> {
// prevent the event from propagating
err.consume();
if (err.getError() != null) {
Log.e(err.getError());
}
Log.sendLogAsync();
Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
});
}
public void start() {
if (current != null) {
current.show();
return;
}
try {
ei = EncodedImage.create("/loading.gif");
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
img = URLImage.createToStorage(ei, url, url, URLImage.RESIZE_SCALE);
LocalNotification n = new LocalNotification();
n.setId("Welcome");
n.setAlertBody("Welcome");
n.setAlertTitle("Welcome");
// n.setAlertSound("/notification_sound_bells.mp3"); //file name must begin with notification_sound
n.setAlertImage(img.toString());
n.setId("5");
n.setBadgeNumber(0);
Display.getInstance().scheduleLocalNotification(
n,
System.currentTimeMillis() + 10 * 1000, // fire date/time
LocalNotification.REPEAT_NONE // Whether to repeat and what frequency
);
if (n.getBadgeNumber() > 0) {
localNotificationReceived("5");
}
hi = new Form("Hi World", BoxLayout.y());
web = new Form("web", BoxLayout.y());
hi.add(new Label("Hi World"));
BrowserComponent browser = new BrowserComponent();
browser.setURL("https://www.codenameone.com/");
web.add(browser);
hi.show();
}
public void localNotificationReceived(String notificationId) {
web.show();
}
public void stop() {
current = getCurrentForm();
if (current instanceof Dialog) {
((Dialog) current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
}
, но в момент нажатия не было выполнено никаких действий . Другая проблема: изображение, переданное в уведомлении, не появилось. Я попытался посмотреть официальную документацию, но ничего полезного не нашел.