在我的应用程序中,我必须在收到通知时播放声音。为了播放音频,我实现了以下代码:
private static final short BFlat = 466; //466.16
private static final short AFlat = 415; //415.30
private static final short A = 440; //440.00
private static final short GFlat = 370; //369.99
private static final short DFlat = 554; //554.37
private static final short C = 523; //523.25
private static final short F = 349; //349.32
// Duration of a 16th note, arbitrary, in ms.
private static final short TEMPO = 125;
// Duration of a 16th note, arbitrary, in ms.
private static final short d16 = 1 * TEMPO;
// Duration of an eighth note, arbitrary, in ms.
private static final short d8 = d16 << 1;
// 10 ms pause.
private static final short dpause = 10;
// Zero frequency pause.
private static final short pause = 0;
private static final short[] TUNE = new short[] {
BFlat, d16, pause, dpause,
BFlat, d16, pause, dpause,
BFlat, d16, pause, dpause,
BFlat, d16, pause, dpause,
A, d16, pause, dpause,
BFlat, d16, pause, dpause,
GFlat, d16, pause, dpause,
GFlat, d16, pause, dpause,
A, d16, pause, dpause,
BFlat, d16, pause, dpause,
DFlat, d16, pause, dpause,
C, d16, pause, dpause, //bar 1
AFlat, d16, pause, dpause,
AFlat, d16, pause, dpause,
AFlat, d16, pause, dpause,
AFlat, d16, pause, dpause,
F, d16, pause, dpause,
GFlat, d16, pause, dpause,
AFlat, d16, pause, dpause,
BFlat, d16, pause, dpause,
AFlat, d16, pause, dpause,
F, d8 + d16 //bar 2
};
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
// % volume
final int VOLUME = 80;
if ( Alert.isAudioSupported())
{
System.out.println("------alert is audio supported-------------"+ Alert.isAudioSupported());
Alert.startAudio(TUNE, 100);
//Alert.startVibrate(5000);
}
Alert.startAudio()
根本没有播放声音。但我可以振动手机。请让我知道我在哪里遗漏了什么或如何在 startAudio 中使用短数组。请给我一些建议或任何想法。谢谢
** * ** *编辑* ** * ** * ** * ** 为了显示对话框和通知,我使用了以下内容。我可以显示对话框并播放振动和铃声,但铃声的音量非常低,除非我将手机放在耳边,否则没人能听到。
try{
Application.getApplication().invokeAndWait(new Runnable() {
public void run()
{
}
});
final Dialog screen = new Dialog(Dialog.D_OK_CANCEL, " "+text,
Dialog.OK,
//mImageGreen.getBitmap(),
null, Manager.VERTICAL_SCROLL);
final UiEngine ui = Ui.getUiEngine();
Application.getApplication().invokeAndWait(new Runnable() {
public void run() {
NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL, 0, null, null);
ui.pushGlobalScreen(screen, 0, UiEngine.GLOBAL_QUEUE);
}
});
System.out.println("-----IN PUSH MESSAGE READER----"+screen.getSelectedValue());
if(screen.getSelectedValue()==1)
{
System.out.println("-----I1-"+screen.getSelectedValue());
ApplicationDescriptor[] appDescriptors =CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("BB_push"));
ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[] {"BB_push"});
try {
ApplicationManager.getApplicationManager().runApplication(appDescriptor);
}catch (ApplicationManagerException e)
{
// TODO Auto-generated catch block
System.out.println("in notification exception----"+e);
e.printStackTrace();
}
}
// screen.setDialogClosedListener(new MyDialogClosedListener());
}
catch (Exception e) {
}
我想在单击确定按钮时打开应用程序,但它不起作用。