0
我想在每週的第一天推送諸如「Hello new week」之類的通知。如何在黑莓手機上按計劃時間發送通知
它每週自動運行。
我已經引用NotificationsDemo通過從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);
}
}
}
按照我們使用的菜單來打開LED的代碼,但我想沒有菜單運行。我會自動運行。
如何正確設置時間來推送我的通知?
@法裏德Farhat的:我做你mentionded什麼,它顯示OK。但我可以永遠查看時間,對話總是在一週的第一天出現。我只在當前時間檢查,如果星期一是對話框顯示,而不是星期一(星期日),則明天不顯示對話框。你可以給我提示,以解決這個問題 –
@ Farid Farhat我已經使用了計時器,並使用這種方法就像這樣'uiApplication.getUiApplication.invokeLater(new runnable(){run(){showmessage(「something」)}}); '但是獲取**非法狀態異常**你是否知道任何其他解決方法 – BBdev
當您嘗試從事件線程外部繪製或訪問UI組件時,出現非法狀態異常。 invokeLater必須爲你解決這個問題。你得到的錯誤信息是什麼?也許我可以幫忙 –