Reputation: 211
In my application i have to play sound when i get notification. For playing audio i have implemented following code:
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()
is not playing sound at all. But I am able to vibrate phone. Please let me know where i am missing something or how i can use array of short in startAudio.
Please suggest me something or any idea.
Thanks
******EDIT************ To display dialog and notification i have used following. I am able to display dialog box and play vibration and ringtone but volume of ringtone is very low, no one can hear unless i dnt keep phone near to my ear.
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) {
}
I want to open app on click of ok button but its not working.
Upvotes: 1
Views: 132
Reputation: 11876
Have you considered using the Notification API? This way, the user would be able to setup your app's notification sound, and have it change appropriately when the notification profile is changed from the home screen - think "Normal" "Vibrate Only" and "All Alerts Off"
Take a look at NotificationsManager and the methods triggerImmediateEvent
and registerSource
Upvotes: 1