Code:
/*
* SmplCallDiverter.java
*
* © <your company here>, 2003-2005
* Confidential and proprietary.
*/
/*
* SmplCallDiverter
*/
package com.blackberrydeveloper.SmplCallDiverter;
import net.rim.blackberry.api.phone.*;
import net.rim.blackberry.api.invoke.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import java.util.*;
import java.lang.*;
import java.io.*;
public final class SmplCallDiverter extends AbstractPhoneListener {
static public void main(String[] args)
{
SmplCallDiverter.registerOnStartup();
}
static private void registerOnStartup()
{
SmplCallDiverter phn_hndl = new SmplCallDiverter();
Phone.addPhoneListener(phn_hndl);
}
private void Dial()
{
PhoneArguments args = new PhoneArguments(PhoneArguments.ARG_CALL,"123456789");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);
}
private boolean SendDigit(String TheNum)
{
PhoneCall PhCll = Phone.getActiveCall();
boolean isOkay;// = True;
isOkay=true;
if ( PhCll != null )
{
isOkay= PhCll.sendDTMFTones(TheNum);
//sleep(200);
}
return isOkay;
}
private SmplCallDiverter(){}
private void checkCall(String ehandler, int callid)
{
PhoneCall callInfo = Phone.getCall(callid);
if ( callInfo != null ) {
/*
* Event Handler: ehandler
* Telephone No.: callInfo.getDisplayPhoneNumber();
* Elapsed Time : callInfo.getElapsedTime();
* Call Status : callInfo.getStatusString();
*/
}
}
// A call has been added to a conference call
public void callAdded(int callId) { checkCall("callAdded", callId); }
// User answered a call
public void callAnswered(int callId)
{ checkCall("callAnswered", callId); }
// Conference call established
public void callConferenceCallEstablished(int callId)
{ checkCall("callConferenceCallEstablished", callId); }
// Network indicates a connected event
public void callConnected(int callId)
{ checkCall("callConnected", callId); }
// Direct-connect call connected
public void callDirectConnectConnected(int callId)
{ checkCall("callDirectConnectConnected", callId); }
// Direct-connect call disconnected
public void callDirectConnectDisconnected(int callId)
{ checkCall("callDirectConnectDisconnected", callId); }
// Call disconnected
public void callDisconnected(int callId)
{ checkCall("callDisconnected", callId); }
// User ended call
public void callEndedByUser(int callId)
{ checkCall("callEndedByUser", callId); }
// Call has been placed on "hold"
public void callHeld(int callId)
{ checkCall("callHeld", callId); }
// New call has arrived
public void callIncoming(int callId)
{
Dialog.alert(" An Incomming Call ");
checkCall("callIncoming", callId);
}
// Outbound call initiated by the handheld
public void callInitiated(int callid)
{
PhoneCall callInfo2 = Phone.getCall(callid);
Dialog.alert(callInfo2.getDisplayPhoneNumber());
Dialog.alert(" The number being dialled is " + callInfo2.getDisplayPhoneNumber());
StringBuffer strBuffer=new StringBuffer(callInfo2.getDisplayPhoneNumber());
// Wrong and Unneeded for(int a=0 ; a < strBuffer.length() ; a++){
int a;
a=1;
//string pls;
//pls="+";
//if ((strBuffer.charAt(a) == "+"))
if((Character.isDigit(strBuffer.charAt(a))))
{
System.out.println( " Starts with a number ");
}
else
{
System.out.println( " It is an international Call ");
Dial();
SendDigit(callInfo2.getDisplayPhoneNumber()); //.charAt(b));
}
//{ System.out.println( " It is an international Call ")
// END the call
/*
EventInjector.KeyCodeEvent pressEndKey=new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_DOWN,( char)Keypad.KEY_END,KeypadListener.STATUS_NOT_FROM_KEYPAD,100);
EventInjector.KeyCodeEvent releaseEndKey=new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_UP,(char)Keypad.KEY_END,KeypadListener.STATUS_NOT_FROM_KEYPAD,100);
EventInjector.invokeEvent(pressEndKey);
EventInjector.invokeEvent(releaseEndKey);
*/
//Dial();
//}
//for(int b=1 ; b < strBuffer.length() ; b++){
//SendDigit(callInfo2.getDisplayPhoneNumber()); //.charAt(b));
checkCall("callInitiated", callid);
}
// Call removed from a conference call
public void callRemoved(int callId)
{ checkCall("callRemoved", callId); }
// Call taken off of "hold"
public void callResumed(int callId)
{ checkCall("callResumed", callId); }
// Call is waiting
public void callWaiting(int callid)
{ checkCall("callWaiting", callid); }
// Conference call has been terminated
// (all members disconnected)
public void conferenceCallDisconnected(int callId)
{ checkCall("conferenceCallDisconnected", callId); }
// Call failed
public void callFailed(int callId, int reason)
{
checkCall("callFailed", callId);
// determine reason
}
}