开发者

How to push a notification with schedule time on Blackberry

I want to push a notification such as "Hello new week" on the first day of each week.

And it run automatically each week.

I have referenced NotificationsDemo by import this project from Blackberry JDE Plugin.

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 );


        }
    }
}

Follow the code we use menu to turn on LED but I want run without menu. I will auto run.

How do I set the time correctly to push my notifications?


Run an alternate entry point which will run a thread and that thread will check the beginning of each week and then display a dialog by using this method:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜