06-04-2009 06:15 AM
Hi,
Is there any other way to reject a incoming call programatically other than using KeyStroke injection??
Rgds,
Siva
Solved! Go to Solution.
06-04-2009 06:46 AM
06-08-2009 08:41 AM
private class CallListener extends AbstractPhoneListener
{
public void callIncoming(int callId){
EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeE vent.KEY_DOWN, ((char)Keypad.KEY_END), KeypadListener.STATUS_ALT, 500);
EventInjector.invokeEvent(ev);
}
06-09-2009 12:48 AM
thanks for the reply,
am able to reject the call using ur code. But the problem is, it disconnects the call only after the phone rings for a short time(makes a Beep). I need to reject the call even before that. Is there a way to do it?
Regards,
Siva
06-09-2009 12:55 AM
06-09-2009 04:14 AM
06-10-2009 08:52 AM - edited 06-10-2009 08:54 AM
@peter- yes , notification APIs can be used in this way. Just implement Phonelistener in your code, and in callincoming() method, just triggerimidiate event, provided a new NotificationId is already registered with Notification manager using Notification constanct - forced.
now in implementation of consequence, startNotification() method will notify you when an incoming call is initiated , and in the body of this method , you can inject red key to reject the call.
here is some code snippt to register the new event,
NotificationsManager.registerSource(NOTIFICATIONS_
ID_1,
new Object()
{
public String toString()
{
return "Profile 1";
}
}
,NotificationsConstants.FORCED);
NotificationsManager.registerConsequence(ConsequenceImpl.ID, new ConsequenceImpl());
NotificationsManager.triggerImmediateEvent(NOTIFICATIONS_ID_1, 0, this, null);
i used this to play custom ringtone on incoming call, instead of default ringtone of current profile.
06-10-2009 09:05 AM
06-11-2009 06:29 AM
i have registered the event source in my main calss and when i tried calling the ConsequenceImpl from my callInComing() method
NotificationsManager.triggerImmediateEvent(NOTIFIC
ATIONS_ID_1, 0, this, null);
but it is not calling the ConsequenceImp.Tried debugging but no luck
06-11-2009 08:57 AM
try this code.
class IncomingCallListener2 extends AbstractPhoneListener { int callId; PhoneCall phoneCall; String incomingCallPhoneNumber; public static final long NOTIFICATIONS_ID_1 = 0xdc5bf2f81374095L; IncomingCallListener2() { Phone.addPhoneListener(this); } public void callIncoming(int callId) { phoneCall = Phone.getCall(callId); incomingCallPhoneNumber = phoneCall.getDisplayPhoneNumber(); //incomingCallPhoneNumber = incomingCallPhoneNumber.substring(7); NotificationsManager.registerSource(NOTIFICATIONS_
ID_1, new Object() { public String toString() { return "Profile 1"; } } ,NotificationsConstants.FORCED); System.out.println("After Firing event1"); NotificationsManager.registerConsequence(Consequen ceImpl.ID, new ConsequenceImpl()); System.out.println("After Firing event 2"); NotificationsManager.triggerImmediateEvent(NOTIFIC ATIONS_ID_1, 0, this, null); System.out.println("After Firing event 3"); } //Event e = new Event(0xbd2350c0dfda2a51L, ++_eventIdGenerator, 500, -1, NotificationsConstants.OUT_OF_HOLSTER_TRIGGER); //e.fire(); */ } } private static final class ConsequenceImpl implements Consequence, SyncConverter { public static final long ID = 0xbd2350c0dfda2a51L; //net.rim.samples.device.notificationsdemo.Notific ationsDemo.ConsequenceImpl private static final int TYPE = 'n' << 24 | 'o' << 16 | 't' << 8 | 'd'; //notd for NotificationsDemo private static final byte[] DATA = new byte[] {'m', 'y', '-', 'c', 'o', 'n', 'f', 'i', 'g', '-', 'o', 'b', 'j', 'e', 'c', 't'}; private static final Configuration CONFIG = new Configuration(DATA); Player p = null; private static final int VOLUME = 80; //% volume /** * A static inner class, describing the Configuration information for this consequence * <p>This implementst the SyncObject interface, although returns a fixed value. */ private static final class Configuration implements SyncObject, Persistable { public byte[] _data; public Configuration(byte[] data) { _data = data; } public int getUID() { return 0; //we're not actually doing any synchronization (vs backup/restore) so we don't care about this value } } public void startNotification(long consequenceID, long sourceID, long eventID, Object configuration, Object context) { EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEv ent.KEY_DOWN, ((char)Keypad.KEY_END), KeypadListener.STATUS_ALT,5000); EventInjector.invokeEvent(ev); } public void stopNotification(long consequenceID, long sourceID, long eventID, Object configuration, Object context) { } /** * It is likely that the following call will return a separate config object for each SourceID, such as data * that describes user set notification settings. However, for this example, we a trivial, arbitrary conifg object */ public Object newConfiguration(long consequenceID, long sourceID, byte profileIndex, int level, Object context) { System.out.println("in newconfiguration method()"); return CONFIG; } /** * Called when there is inbound (from the desktop) data to be converted to object form */ public SyncObject convert(DataBuffer data, int version, int UID) { //it's up to us to write and read the data. we apply a four byte type and a 4 byte length, and then the raw data try { int type = data.readInt(); int length = data.readCompressedInt(); if ( type == TYPE ) { byte[] rawdata = new byte[length]; data.readFully(rawdata); return new Configuration(rawdata); } } catch (EOFException e) { //we've prematurely reached the end of the DataBuffer System.err.println(e); } return null; } public boolean convert(SyncObject object, DataBuffer buffer, int version) { boolean retval = false; if ( object instanceof Configuration ) { Configuration c = (Configuration)object; buffer.writeInt(TYPE); buffer.writeCompressedInt(c._data.length); buffer.write(c._data); retval = true; } return retval; } }