Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android CN1中的LocalNofication声音_Android_Ios_Codenameone - Fatal编程技术网

Android CN1中的LocalNofication声音

Android CN1中的LocalNofication声音,android,ios,codenameone,Android,Ios,Codenameone,无论是在Android上还是在iOS上,都不会播放LocalNotification实例引用的声音文件(请查看下面的示例代码)。在安卓系统上,播放系统的标准声音。有人知道我做错了什么吗 @Override protected void postMain(Form f) { Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout(BorderLayout.CENTER_B

无论是在Android上还是在iOS上,都不会播放
LocalNotification
实例引用的声音文件(请查看下面的示例代码)。在安卓系统上,播放系统的标准声音。有人知道我做错了什么吗

@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);
}

注意:通知\声音\文件.mp3确实存在于我的默认软件包中

如果要从设备存储器获取声音文件,则无法直接检测 而不是用这个

ntf.setAlertSound("/" + soundFileName);
试试这个

ntf.setAlertSound(Environment.getExternalStorageDirectory().getAbsolutePath() + "Folder_Name/" + soundFileName);
这将定位您的文件,并播放您的特定声音。还有一件事是在清单中添加“android.permission.READ\u EXTERNAL\u STORAGE”权限。
祝你好运。

如果你想从设备存储器中获取声音文件,那么它无法直接检测 而不是用这个

ntf.setAlertSound("/" + soundFileName);
试试这个

ntf.setAlertSound(Environment.getExternalStorageDirectory().getAbsolutePath() + "Folder_Name/" + soundFileName);
这将定位您的文件,并播放您的特定声音。还有一件事是在清单中添加“android.permission.READ\u EXTERNAL\u STORAGE”权限。
祝您好运。

声音文件需要是
文件系统存储中文件的路径,该文件必须始终是完全限定的。您需要将文件复制到应用程序目录下的文件系统中。请参见

声音文件需要是
FileSystemStorage
中文件的路径,该文件必须始终是完全限定的。您需要将文件复制到应用程序目录下的文件系统中,请参见

,感谢您的快速响应,但这不是CN1中可以处理的方式。e、 g.
Environmet
在CN1范围内不可用。此外,sothanks说,这是一种快速反应,但这不是CN1可以处理的方式。e、 g.
Environmet
在CN1范围内不可用。此外,sohmm说我很困惑,因为当我通过一个完全限定的路径时,我得到了以下错误:“
警报声音文件名必须以'notification_sound'前缀开头”(该方法的java文档中也有说明)。这就是我传递“/notification\u sound\u file.mp3”的原因。对不起,我想我不熟悉那个API。我会让从事这项工作的人调查一下ithmm,我很困惑,因为当我通过一个完全限定的路径时,我得到了以下错误:“
警报声音文件名必须以'notification\u sound'前缀开头”
”(该方法的java文档中也有说明)。这就是我传递“/notification\u sound\u file.mp3”的原因。对不起,我想我不熟悉那个API。我会请从事这项工作的人调查一下这看起来像是代号一中的一个bug。我提出了一个问题。目前似乎没有解决方法。这看起来像是代号1中的一个bug。我提出了一个问题。目前看来没有解决这个问题的办法。