2013-03-18 97 views
1

在我的应用程序中,当我收到通知时,我必须播放声音。用于播放音频我已经实现下面的代码:黑莓手机通知中播放音频

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) { 
         } 

我想打开应用程序点击确定按钮,但它不工作。

回答

1

您是否考虑过使用Notification API?通过这种方式,用户将能够设置您的应用程序的通知声音,并把它适当地改变时通知配置文件从主屏幕改变 - 认为“正常”,“仅振动”和“关闭所有提醒”

取看看NotificationsManager和方法triggerImmediateEventregisterSource

+0

感谢rply。我以这种方式使用NotificationManager类: - NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL,0,null,null); ui.pushGlobalScreen(screen,0,UiEngine.GLOBAL_QUEUE);但它不是在说... – suprita 2013-03-19 06:20:42