無論是在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)。目前看起來沒有解決方法。 –