PDA

View Full Version : Java and a telephone


squirellplaying
07-03-2005, 09:09 PM
I've been messing around a little with my phone and have it so it plugs into the modem in my computer from the wall then to the phone.
[Wall Jack] ----- [Computer]------[Phone]

I don't know if this is even possible but on incoming calls is it possible to get the phone number from the call using Java? I've tried to use the Java Telephony API (http://java.sun.com/products/jtapi/), but have had no luck. It can never find the provider for incoming or outgoing calls. I'm just using the example code they're provided:

Incoming

import javax.telephony.*;
import javax.telephony.events.*;

/*
* The MyInCallObserver class implements the CallObserver and
* recieves all Call-related events.
*/

class MyInCallObserver implements CallObserver {

public void callChangedEvent(CallEv[] evlist) {
TerminalConnection termconn;
String name;
for (int i = 0; i < evlist.length; i++) {

if (evlist[i] instanceof TermConnEv) {
termconn = null;
name = null;

try {
TermConnEv tcev = (TermConnEv)evlist[i];
Terminal term = termconn.getTerminal();
termconn = tcev.getTerminalConnection();
name = term.getName();
} catch (Exception excp) {
// Handle exceptions.
}

String msg = "TerminalConnection to Terminal: " + name + " is ";

if (evlist[i].getID() == TermConnActiveEv.ID) {
System.out.println(msg + "ACTIVE");
}
else if (evlist[i].getID() == TermConnRingingEv.ID) {
System.out.println(msg + "RINGING");

/* Answer the telephone Call using "inner class" thread */
try {
final TerminalConnection _tc = termconn;
Runnable r = new Runnable() {
public void run(){
try{
_tc.answer();
} catch (Exception excp){
// handle answer exceptions
}
};

};
Thread T = new Thread(r);
T.start();
} catch (Exception excp) {
// Handle Exceptions;
}
} else if (evlist[i].getID() == TermConnDroppedEv.ID) {
System.out.println(msg + "DROPPED");
}
}
}
}
}



/*
* Create a provider and monitor a particular terminal for an incoming call.
*/
public class Incall {

public static final void main(String args[]) {

/*
* Create a provider by first obtaining the default implementation of
* JTAPI and then the default provider of that implementation.
*/
Provider myprovider = null;
try {
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
myprovider = peer.getProvider(null);
} catch (Exception excp) {
System.out.println("Can't get Provider: " + excp.toString());
System.exit(0); //Execution ends here.
}

/*
* Get the terminal we wish to monitor and add a call observer to that
* Terminal. This will place a call observer on all call which come to
* that terminal. We are assuming that Terminals are named after some
* primary telephone number on them.
*/
try {
Terminal terminal = myprovider.getTerminal("4761111");
terminal.addCallObserver(new MyInCallObserver());
} catch (Exception excp) {
System.out.println("Can't get Terminal: " + excp.toString());
System.exit(0);
}
}
}

Antoniohawk
07-08-2005, 02:39 AM
Very interesting. That looks like something that I'll need to look into as soon as I crack this dumb payphone open. :D I'm not sure what your problem may be, but do that suggestions for setting up the hardware, such as what needs to be plugged where?