Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
shiv_inf
Posts: 28
Registered: ‎04-24-2009
My Device: Not Specified
Accepted Solution

Reject a call Programatically

Hi,

 

Is there any other way to reject a incoming call programatically other than using KeyStroke injection??

 

Rgds,

Siva

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Reject a call Programatically

yes, in OS <4.5 this was possible by executing menu items of the phone application. look it up on the forum.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
amardeepjaiman
Posts: 293
Registered: ‎02-25-2009
My Device: Not Specified

Re: Reject a call Programatically

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

 

}

Please use plain text.
New Developer
shiv_inf
Posts: 28
Registered: ‎04-24-2009
My Device: Not Specified

Re: Reject a call Programatically

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

Please use plain text.
Developer
amardeepjaiman
Posts: 293
Registered: ‎02-25-2009
My Device: Not Specified

Re: Reject a call Programatically

Yes, Use notification apis.
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Reject a call Programatically

@amardeepjaiman - I was not aware that the Notification API could be used in this way.  Can you describe in overview (I don't want code) how this works?
Please use plain text.
Developer
amardeepjaiman
Posts: 293
Registered: ‎02-25-2009
My Device: Not Specified

Re: Reject a call Programatically

[ Edited ]

@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.

 

Message Edited by amardeepjaiman on 06-10-2009 06:24 PM
Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Reject a call Programatically

that's evil. i like it!
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
shiv_inf
Posts: 28
Registered: ‎04-24-2009
My Device: Not Specified

Re: Reject a call Programatically

i have registered the  event source in my main calss and when i tried calling the ConsequenceImpl from my callInComing() method

NotificationsManager.triggerImmediateEvent(NOTIFICATIONS_ID_1, 0, this, null);

 

but it is not calling the ConsequenceImp.Tried debugging but no luck :smileysad:

am i missing something...
Please use plain text.
Developer
amardeepjaiman
Posts: 293
Registered: ‎02-25-2009
My Device: Not Specified

Re: Reject a call Programatically

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(ConsequenceImpl.ID, new ConsequenceImpl()); System.out.println("After Firing event 2"); NotificationsManager.triggerImmediateEvent(NOTIFICATIONS_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.NotificationsDemo.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.KeyCodeEvent.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; } }

 

 

 

Please use plain text.