[英]LocalNofication sound in CN1
Neither on Android nor on iOS the sound file referenced by a LocalNotification
instance is played (check the sample code below). 在Android和iOS上都没有播放
LocalNotification
实例引用的声音文件(请查看下面的示例代码)。 On Android the system's standard sound is played. 在Android上播放系统的标准声音。 Anyone knows what I am doing wrong here?
谁知道我在做错了什么?
@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);
}
Note: notification_sound_file.mp3 does exist in my default package! 注意:我的默认包中确实存在notification_sound_file.mp3 !
If you want to get the sound file from device storage, then it can't detect directly Instead of using this 如果你想从设备存储中获取声音文件,那么它无法直接检测而不是使用它
ntf.setAlertSound("/" + soundFileName);
Try this 尝试这个
ntf.setAlertSound(Environment.getExternalStorageDirectory().getAbsolutePath() + "Folder_Name/" + soundFileName);
This will locate your file and your specific sound will play. 这将找到您的文件,您的特定声音将播放。 One more thing add "android.permission.READ_EXTERNAL_STORAGE" permission also in manifest.
还有一件事是在清单中添加“android.permission.READ_EXTERNAL_STORAGE”权限。 Best of luck.
祝你好运。
The sound file needs to be a path to a file in FileSystemStorage
which must always be fully qualified. 声音文件必须是
FileSystemStorage
中文件的路径,该文件必须始终完全限定。 You need to copy the file into the filesystem ideally under the app directory see https://www.codenameone.com/how-do-i-use-storage-file-system-sql.html 您需要将文件理想地复制到文件系统的app目录下,请参阅https://www.codenameone.com/how-do-i-use-storage-file-system-sql.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.