BlackBerry - Как создать событие тревоги? - PullRequest
3 голосов
/ 04 февраля 2010

Я хочу получить сигнал тревоги. в моем приложении я успешно получил доступ к календарю и назначил встречу, но как я могу получить доступ к тревоге. Помогите мне, пожалуйста. ниже мой код

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

Ответы [ 2 ]

2 голосов
/ 17 марта 2010
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
}
0 голосов
/ 05 сентября 2012
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);
        }
    }
...