开发者

BlackBerry - How to create alarm event?

开发者 https://www.devze.com 2022-12-18 20:35 出处:网络
I want to acces alarm. in my application i have successfully accessed calender and have set the appointment but how i can access alarm. please help me. following is my code

I want to acces alarm. in my application i have successfully accessed calender and have set the appointment but how i can access alarm. please help me. following is my code

public class Alarm 
{
    private Event event;
    public void myAlarm()
    {
        try
        {
            EventList eventList = (EventList)PIM.getInstance().
            openPIMList(PIM.EVENT_LIST, PIM.WRITE_ONLY);
            event = eventList.createEvent();
            event.addString(event.SUMMARY, PIMItem.ATTR_NONE, "My alarm");
           开发者_Go百科 event.addString(event.LOCATION, PIMItem.ATTR_NONE, "My Location");
            event.addDate(event.END, PIMItem.ATTR_NONE, 
                System.currentTimeMillis()+360000);
            event.addDate(event.START, PIMItem.ATTR_NONE, 
                System.currentTimeMillis()+120000);
            event.commit();
        }//end of try block
        catch(Exception e){}    
    }//end of method myAlarm    
}//end of main class Alarm


EventList evList = (EventList) PIM.getInstance().openPIMList(PIM.EVENT_LIST,
    PIM.READ_WRITE);
BlackBerryEvent ev = (BlackBerryEvent) evList.createEvent();

if (evList.isSupportedField(BlackBerryEvent.ALARM)) {
 ev.addInt(BlackBerryEvent.ALARM, BlackBerryEvent.ATTR_NONE, 180); //3 min = 180 
 //if this field has a value of 180, then the alarm first occurs 180 seconds before the
 date/time value specified by Event.START
}


if(field == save)
    {
        try 
        {
            events = (EventList) PIM.getInstance().openPIMList( PIM.EVENT_LIST,PIM.READ_WRITE );
        } 
        catch( PIMException e ) 
        {
            System.out.println("++++++++++++++++++++++++++++++++++"+e);
            return;
        }
        Event event = events.createEvent();
        if( events.isSupportedField( Event.SUMMARY ) )
            event.addString( Event.SUMMARY, PIMItem.ATTR_NONE, "Meeting with John" );

        if( events.isSupportedField( Event.LOCATION ) )
            event.addString( Event.LOCATION, PIMItem.ATTR_NONE, "Amritsar" );
        if( events.isSupportedField( Event.START ) )
            event.addDate( Event.START, PIMItem.ATTR_NONE, aDate.getDate()+60000);
        System.out.println("System.currentTimeMillis()+60000 : "+System.currentTimeMillis()+60000);
        if( events.isSupportedField( Event.END ) )
            event.addDate( Event.END, PIMItem.ATTR_NONE, aDate.getDate()+120000);
        System.out.println("System.currentTimeMillis()+120000 : "+System.currentTimeMillis());
        if( events.isSupportedField( Event.ALARM ) )
        {
                event.addInt( Event.ALARM, PIMItem.ATTR_NONE, 900);
        }       
        if( events.isSupportedField( Event.NOTE ) )
            event.addString( Event.NOTE, PIMItem.ATTR_NONE,"I phoned on Monday to book this meeting" );
        try 
        {
            if( events.maxCategories() != 0 && events.isCategory( "Work" ) )
                event.addToCategory( "Work" );          
        }
        catch (PIMException e1) 
        {   
            e1.printStackTrace();
        }
        try 
        {
            event.commit();
        } 
        catch( PIMException e ) 
        {
            System.out.println("++++++++++++++++++++++++++++++++++"+e);
        }    
        try 
        {
            events.close();
        } 
        catch( PIMException e ) 
        {
            System.out.println("++++++++++++++++++----------------"+e);
        }
    }
0

精彩评论

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

关注公众号