2011-09-09 10 views
0

毎週1日に「こんにちは新年」などの通知を送りたいと思います。ブラックベリーで予定時刻の通知をプッシュする方法

そして、毎週自動的に実行されます。

私はBlackberry JDE PluginからこのプロジェクトをインポートしてNotificationsDemoを参照しました。

public final class NotificationsDemo extends UiApplication 
{  
    // com.rim.samples.device.notificationsdemo.NOTIFICATIONS_ID_1 
    static final long NOTIFICATIONS_ID_1 = 0xdc5bf2f81374095L; 

    /** 
    * Entry point for application. 
    * @param args Command-line arguments 
    */ 
    public static void main(String[] args) 
    { 
     if(args.length > 0 && args[ 0 ].equals("autostartup")) 
     { 
      NotificationsDemo nd = new NotificationsDemo(); 
      nd.registerNotificationObjects(); 

      // Keep this instance around for rendering 
      // Notification dialogs. 
      nd.enterEventDispatcher(); 
     } 
     else 
     { 
      // Start a new app instance for GUI operations. 
      new NotificationsDemo().showGui(); 
     } 
    } 

    /** 
    * Displays the NotificationDemoScreen. 
    */ 
    private void showGui() 
    { 
     // Create a new instance of the application and make the currently 
     // running thread the application's event dispatch thread. 
     pushScreen(new NotificationsDemoScreen()); 
     enterEventDispatcher(); 
    } 

    /** 
    * Registers this application as the notification manager. 
    */ 
    private void registerNotificationObjects() 
    { 
     // A source is registered to tell the system that our application will 
     // be sending notification events. This will will cause a new user 
     // editable configuration to be added to the Profiles application. 
     NotificationsManager.registerSource(NOTIFICATIONS_ID_1, new Object() 
     { 
      public String toString() 
      { 
       return "Notifications Demo"; 
      } 
     }, NotificationsConstants.IMPORTANT); 

     // Our NotificationsEngineListener implementation will display a dialog 
     // to the user when a deferred event is triggered. 
     NotificationsManager.registerNotificationsEngineListener(NOTIFICATIONS_ID_1, 
       new NotificationsEngineListenerImpl(this));   

     // Our Consequence implementation will invoked whenever an immediate 
     // event occurs.   
     NotificationsManager.registerConsequence(ConsequenceImpl.ID, new ConsequenceImpl()); 
    } 

    /** 
    * The MainScreen class for our UiApplication. 
    */ 
    private static class NotificationsDemoScreen extends MainScreen 
    { 
     private long _eventId; 

     // Constructor 
     private NotificationsDemoScreen() 
     { 
      // Initialize UI components.    
      setTitle("Notifications Demo"); 
      add(new RichTextField("Trigger notification from menu.")); 

      //A menu item to generate immediate and deferred events. 
      MenuItem notifyItem = new MenuItem(new StringProvider("Notify (ID1)"), 0x230010, 0); 
      notifyItem.setCommand(new Command(new CommandHandler() 
      { 
       /** 
       * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata, Object) 
       */ 
       public void execute(ReadOnlyCommandMetadata metadata, Object context) 
       { 
        int trigger = NotificationsConstants.MANUAL_TRIGGER; 

        // The timeout parameter is IGNORED unless the TRIGGER 
        // is OUT_OF_HOLSTER_TRIGGER. 
        long timeout = -1; 

        Event e = new Event(NotificationsDemo.NOTIFICATIONS_ID_1, _eventId, 500, timeout, 
          trigger); 
        _eventId++; 
        e.fire(); 
       } 
      })); 
      addMenuItem(notifyItem); 


     } 
    } 
} 

LEDをオンにするメニューを使用するコードに従いますが、メニューなしで実行する必要があります。私は自動実行されます。

通知をプッシュするために時間を正しく設定するにはどうすればよいですか?

答えて

0

は、スレッドを実行すると、そのスレッドがそれぞれ週の始まりをチェックしてから、このメソッドを使用してダイアログを表示する別のエントリ・ポイントを実行します。

private void showMessage(String data) { 
    UiEngine ui = Ui.getUiEngine(); 
    Screen screen = new Dialog(Dialog.D_OK, data, Dialog.OK, 
    Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), 
    Manager.VERTICAL_SCROLL); 
    ui.queueStatus(screen, 1, true); 
} 
+0

ファリドFarhat @:私はあなたがmentionded何をしたとOKと表示されます。しかし、私は時間を永遠にチェックすることができ、ダイアログは常に週の最初の曜日に表示されます。私は現在の時刻のみをチェックし、月曜日がダイアログ表示で、月曜日(元日曜日)でない場合、ダイアログは明日表示されません。この問題を解決するためのヒントを教えてください。 –

+0

@Farid Farhat私はそこでタイマーを使用していましたが、このようなメソッドを使用しました。このuiApplication.getUiApplication.invokeLater(new runnable(){run(){showmessage( "something")}}); 'を取得しています**違法例外の状態**その他の回避策を知っていますか – BBdev

+0

イベントスレッド外からUIコンポーネントを描画またはアクセスしようとすると、不正な状態例外が表示されます。 invokeLaterはこれを解決する必要があります。あなたが得ているエラーのメッセージは何ですか?たぶん私はそれを助けることができます –

関連する問題