在我的应用程序中,我必须在收到通知时播放声音。为了播放音频,我实现了以下代码:
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中使用short的数组。
请建议我一些或任何想法。
感谢
的 的 ** * ** * 修改的 * ** * ** * ** * ** 要显示我使用过的对话框和通知。我可以显示对话框并播放振动和铃声,但是铃声音量非常低,除非我把手机放在耳边,否则没有人能听到。
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) {
}
我想点击确定按钮打开应用程序,但它无效。
答案 0 :(得分:1)
您是否考虑过使用Notification API?通过这种方式,用户可以设置应用程序的通知声音,并在主屏幕更改通知配置文件时进行相应更改 - 认为“正常”“仅振动”和“所有警报关闭”
查看NotificationsManager以及方法triggerImmediateEvent
和registerSource