无论是在Android还是iOS上,都会播放LocalNotification
实例引用的声音文件(请查看下面的示例代码)。在Android上播放系统的标准声音。任何人都知道我在这里做错了什么?CN1中的LocalNofication声音
@Override
protected void postMain(Form f) {
Container contentPane = f.getContentPane();
contentPane.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
contentPane.setUIID("ToastBar");
Button btn = new Button("create Notification");
btn.addActionListener((e) -> {
scheduleNotification(Display.getInstance(), 0, "Title", "Body", "notification_sound_file.mp3", System.currentTimeMillis() + 1000);
});
contentPane.add(BorderLayout.CENTER, btn);
}
private void scheduleNotification(Display dsp, int nId, String nTitle, String nBody, String soundFileName, long scheduleTime) {
LocalNotification ntf = new LocalNotification();
ntf.setId(nId + " " + scheduleTime);
ntf.setAlertTitle(nTitle);
ntf.setAlertBody(nBody + " " + scheduleTime);
ntf.setAlertSound("/" + soundFileName);
Log.p("scheduling ntf ("+nTitle+","+ ntf.getAlertBody() +","+ ntf.getAlertSound());
dsp.scheduleLocalNotification(ntf, scheduleTime, LocalNotification.REPEAT_NONE);
}
注:notification_sound_file.mp3在我的默认包确实存在!
这看起来像Codename One中的一个错误。我在这里提出了一个问题(https://github.com/codenameone/CodenameOne/issues/2137)。目前看起来没有解决方法。 –