views:

352

answers:

1

i have invoked blackberry calender from my application
can anyone tell me how to fetch :

  • date
  • duration
  • notes

from the selected date

my code :

 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  A: 

You should register custom menu item for calendar application.

See How To - Add a custom menu item to an existing BlackBerry application

UPDATE
alt textalt textalt textalt text

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);
    }
}
Max Gontar
the calender application gets opened when i click on menu itembut i am unable to fetch date,duration,notes for particular date that user selectsy to use custom menu???????????
SWATI
thanks so much it worked!!!!!!!!
SWATI
you're welcome :)
Max Gontar