BlackBerry - 以编程方式获取日历中的数据

时间:2010-03-24 08:56:54

标签: blackberry calendar integration

我从我的申请中调用了黑莓日历 任何人都可以告诉我如何获取:

  • 日期
  • 持续时间
  • 注释

从所选日期

我的代码:

 MenuItem importCalender = new MenuItem("Import from Calender",100,11)
   {
    public void run() 
    {
     UiApplication.getUiApplication().invokeAndWait(new Runnable()
     {
      public void run()
      { 
       try 
       {
          EventList list = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);



          Enumeration events = list.items();
          BlackBerryEvent e = (BlackBerryEvent) events.nextElement();


          Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR, new CalendarArguments( CalendarArguments.ARG_VIEW_DEFAULT,e) );


       } 
       catch (PIMException e) 
       {

        //e.printStackTrace();
       }
      }
     });
    }

   };
  protected void makeMenu(Menu menu, int instance)
   { 
   menu.add(importCalender);
  }

1 个答案:

答案 0 :(得分:1)

您应该为日历应用程序注册自定义菜单项。

请参阅How To - Add a custom menu item to an existing BlackBerry application

<强>更新
alt text http://img228.imageshack.us/img228/5350/caledar1.jpg alt text http://img413.imageshack.us/img413/6417/caledar2.jpg alt text http://img517.imageshack.us/img517/2789/caledar3.jpg alt text http://img401.imageshack.us/img401/4959/caledar4.jpg

class Scr extends MainScreen {
    VerticalFieldManager mManager;
    UiApplication mApp;

    public Scr() {
        mApp = UiApplication.getUiApplication();
        mManager = (VerticalFieldManager) this.getMainManager();
        MyMenuItem myMenuitem = new MyMenuItem(0);
        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_CALENDAR, myMenuitem);

    }

    class MyMenuItem extends ApplicationMenuItem {
        MyMenuItem(int order) {
            super(order);
        }

        public Object run(Object context) {
            if (context instanceof Event) {
                Event event = (Event) context;
                final String text = "start: "
                        + (new Date(event.getDate(Event.START, 0))).toString()
                        + "\nend: "
                        + (new Date(event.getDate(Event.END, 0))).toString()
                        + "\nnote: " + event.getString(Event.NOTE, 0);
                String message = "Import event\n" + text;

                if (Dialog.YES == Dialog.ask(Dialog.D_YES_NO, message)) {

                    mApp.invokeLater(new Runnable() {
                        public void run() {
                            mApp.requestForeground();
                            mManager.add(new LabelField(text));
                        }
                    });
                }
            }
            return context;
        }

        public String toString() {
            return "Import Event";
        }
    }

    MenuItem importCalender = new MenuItem("Import from Calender", 100, 11) {
        public void run() {
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                public void run() {
                    Invoke.invokeApplication(Invoke.APP_TYPE_CALENDAR,
                            new CalendarArguments(
                                    CalendarArguments.ARG_VIEW_DEFAULT));
                }
            });
        }
    };

    protected void makeMenu(Menu menu, int instance) {
        menu.add(importCalender);
    }
}